Skip to Content
Odoo Menu
  • Sign in
  • Try it free
  • Apps
    Finance
    • Accounting
    • Invoicing
    • Expenses
    • Spreadsheet (BI)
    • Documents
    • Sign
    Sales
    • CRM
    • Sales
    • POS Shop
    • POS Restaurant
    • Subscriptions
    • Rental
    Websites
    • Website Builder
    • eCommerce
    • Blog
    • Forum
    • Live Chat
    • eLearning
    Supply Chain
    • Inventory
    • Manufacturing
    • PLM
    • Purchase
    • Maintenance
    • Quality
    Human Resources
    • Employees
    • Recruitment
    • Time Off
    • Appraisals
    • Referrals
    • Fleet
    Marketing
    • Social Marketing
    • Email Marketing
    • SMS Marketing
    • Events
    • Marketing Automation
    • Surveys
    Services
    • Project
    • Timesheets
    • Field Service
    • Helpdesk
    • Planning
    • Appointments
    Productivity
    • Discuss
    • Approvals
    • IoT
    • VoIP
    • Knowledge
    • WhatsApp
    Third party apps Odoo Studio Odoo Cloud Platform
  • Industries
    Retail
    • Book Store
    • Clothing Store
    • Furniture Store
    • Grocery Store
    • Hardware Store
    • Toy Store
    Food & Hospitality
    • Bar and Pub
    • Restaurant
    • Fast Food
    • Guest House
    • Beverage Distributor
    • Hotel
    Real Estate
    • Real Estate Agency
    • Architecture Firm
    • Construction
    • Estate Management
    • Gardening
    • Property Owner Association
    Consulting
    • Accounting Firm
    • Odoo Partner
    • Marketing Agency
    • Law firm
    • Talent Acquisition
    • Audit & Certification
    Manufacturing
    • Textile
    • Metal
    • Furnitures
    • Food
    • Brewery
    • Corporate Gifts
    Health & Fitness
    • Sports Club
    • Eyewear Store
    • Fitness Center
    • Wellness Practitioners
    • Pharmacy
    • Hair Salon
    Trades
    • Handyman
    • IT Hardware & Support
    • Solar Energy Systems
    • Shoe Maker
    • Cleaning Services
    • HVAC Services
    Others
    • Nonprofit Organization
    • Environmental Agency
    • Billboard Rental
    • Photography
    • Bike Leasing
    • Software Reseller
    Browse all Industries
  • Community
    Learn
    • Tutorials
    • Documentation
    • Certifications
    • Training
    • Blog
    • Podcast
    Empower Education
    • Education Program
    • Scale Up! Business Game
    • Visit Odoo
    Get the Software
    • Download
    • Compare Editions
    • Releases
    Collaborate
    • Github
    • Forum
    • Events
    • Translations
    • Become a Partner
    • Services for Partners
    • Register your Accounting Firm
    Get Services
    • Find a Partner
    • Find an Accountant
      • Get a Tailored Demo
    • Implementation Services
    • Customer References
    • Support
    • Upgrades
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +32 2 290 34 90
    • Get a Tailored Demo
  • Pricing
  • Help
  1. APPS
  2. Extra Tools
  3. Base Rest v 11.0
  4. Sales Conditions FAQ

Base Rest

by ACSONE SA/NV https://github.com/OCA/rest-framework , Odoo Community Association (OCA) https://github.com/OCA/rest-framework
Odoo
v 11.0 v 12.0 Third Party 1918
Download for v 11.0 Deploy on Odoo.sh
Apps purchases are linked to your Odoo account, please sign in or sign up first.
Availability
Odoo Online
Odoo.sh
On Premise
Community Apps Dependencies Show
Components
Lines of code 1241
Technical Name base_rest
LicenseLGPL-3
Websitehttps://github.com/OCA/rest-framework
Versions 11.0 12.0 14.0 15.0 16.0
You bought this module and need support? Click here!

Base Rest

Beta License: LGPL-3 OCA/rest-framework Translate me on Weblate Try me on Runboat

This addon provides the basis to develop high level REST APIs for Odoo.

As Odoo becomes one of the central pieces of enterprise IT systems, it often becomes necessary to set up specialized service interfaces, so existing systems can interact with Odoo.

While the XML-RPC interface of Odoo comes handy in such situations, it requires a deep understanding of Odoo’s internal data model. When used extensively, it creates a strong coupling between Odoo internals and client systems, therefore increasing maintenance costs.

Table of contents

  • Configuration
  • Usage
  • Known issues / Roadmap
  • Changelog
    • 12.0.2.0.1
    • 11.0.2.0.0
    • 11.0.1.0.1
    • 11.0.1.0.0
  • Bug Tracker
  • Credits
    • Authors
    • Contributors
    • Maintainers

Configuration

If an error occurs when calling a method of a service (ie missing parameter, ..) the system returns only a general description of the problem without details. This is done on purpose to ensure maximum opacity on implementation details and therefore lower security issue.

This restriction can be problematic when the services are accessed by an external system in development. To know the details of an error it is indeed necessary to have access to the log of the server. It is not always possible to provide this kind of access. That’s why you can configure the server to run these services in development mode.

To run the REST API in development mode you must add a new section ‘[base_rest]’ with the option ‘dev_mode=True’ in the server config file.

[base_rest]
dev_mode=True

When the REST API runs in development mode, the original description and a stack trace is returned in case of error. Be careful to not use this mode in production.

Usage

To add your own REST service you must provides at least 2 classes.

  • A Component providing the business logic of your service,
  • A Controller to register your service.

The business logic of your service must be implemented into a component (odoo.addons.component.core.Component) that inherit from ‘base.rest.service’

from odoo.addons.component.core import Component


class PingService(Component):
    _inherit = 'base.rest.service'
    _name = 'ping.service'
    _usage = 'ping'
    _collection = 'my_module.services'


    # The following method are 'public' and can be called from the controller.
    def get(self, _id, message):
        return {
            'response': 'Get called with message ' + message}

    def search(self, message):
        return {
            'response': 'Search called search with message ' + message}

    def update(self, _id, message):
        return {'response': 'PUT called with message ' + message}

    # pylint:disable=method-required-super
    def create(self, **params):
        return {'response': 'POST called with message ' + params['message']}

    def delete(self, _id):
        return {'response': 'DELETE called with id %s ' % _id}

    # Validator
    def _validator_search(self):
        return {'message': {'type': 'string'}}

    # Validator
    def _validator_get(self):
        # no parameters by default
        return {}

    def _validator_update(self):
        return {'message': {'type': 'string'}}

    def _validator_create(self):
        return {'message': {'type': 'string'}}

Once your have implemented your services (ping, …), you must tell to Odoo how to access to these services. This process is done by implementing a controller that inherits from odoo.addons.base_rest.controllers.main.RestController

from odoo.addons.base_rest.controllers import main

class MyRestController(main.RestController):
    _root_path = '/my_services_api/'
    _collection_name = my_module.services

In your controller, _’root_path’ is used to specify the root of the path to access to your services and ‘_collection_name’ is the name of the collection providing the business logic for the requested service/

By inheriting from RestController the following routes will be registered to access to your services

@route([
    ROOT_PATH + '<string:_service_name>',
    ROOT_PATH + '<string:_service_name>/search',
    ROOT_PATH + '<string:_service_name>/<int:_id>',
    ROOT_PATH + '<string:_service_name>/<int:_id>/get'
], methods=['GET'], auth="user", csrf=False)
def get(self, _service_name, _id=None, **params):
    method_name = 'get' if _id else 'search'
    return self._process_method(_service_name, method_name, _id, params)

@route([
    ROOT_PATH + '<string:_service_name>',
    ROOT_PATH + '<string:_service_name>/<string:method_name>',
    ROOT_PATH + '<string:_service_name>/<int:_id>',
    ROOT_PATH + '<string:_service_name>/<int:_id>/<string:method_name>'
], methods=['POST'], auth="user", csrf=False)
def modify(self, _service_name, _id=None, method_name=None, **params):
    if not method_name:
        method_name = 'update' if _id else 'create'
    if method_name == 'get':
        _logger.error("HTTP POST with method name 'get' is not allowed. "
                      "(service name: %s)", _service_name)
        raise BadRequest()
    return self._process_method(_service_name, method_name, _id, params)

@route([
    ROOT_PATH + '<string:_service_name>/<int:_id>',
], methods=['PUT'], auth="user", csrf=False)
def update(self, _service_name, _id, **params):
    return self._process_method(_service_name, 'update', _id, params)

@route([
    ROOT_PATH + '<string:_service_name>/<int:_id>',
], methods=['DELETE'], auth="user", csrf=False)
def delete(self, _service_name, _id):
    return self._process_method(_service_name, 'delete', _id)

The HTTP GET ‘http://my_odoo/my_services_api/ping’ will be dispatched to the method PingService.search

Known issues / Roadmap

The roadmap and known issues can be found on GitHub.

Changelog

12.0.2.0.1

  • _validator_…() methods can now return a cerberus Validator object instead of a schema dictionnary, for additional flexibility (e.g. allowing validator options such as allow_unknown).

11.0.2.0.0

  • Licence changed from AGPL-3 to LGPL-3

11.0.1.0.1

  • Fix issue when rendering the jsonapi documentation if no documentation is provided on a method part of the REST api.

11.0.1.0.0

First official version. The addon has been incubated into the Shopinvader repository from Akretion. For more information you need to look at the git log.

Bug Tracker

Bugs are tracked on GitHub Issues. In case of trouble, please check there if your issue has already been reported. If you spotted it first, help us to smash it by providing a detailed and welcomed feedback.

Do not contact contributors directly about support or help with technical issues.

Credits

Authors

  • ACSONE SA/NV

Contributors

  • Laurent Mignon <laurent.mignon@acsone.eu>
  • Sébastien Beau <sebastien.beau@akretion.com>

Maintainers

This module is maintained by the OCA.

Odoo Community Association

OCA, or the Odoo Community Association, is a nonprofit organization whose mission is to support the collaborative development of Odoo features and promote its widespread use.

Current maintainer:

lmignon

This module is part of the OCA/rest-framework project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

Please log in to comment on this module

  • The author can leave a single reply to each comment.
  • This section is meant to ask simple questions or leave a rating. Every report of a problem experienced while using the module should be addressed to the author directly (refer to the following point).
  • If you want to start a discussion with the author, please use the developer contact information. They can usually be found in the description.
Please choose a rating from 1 to 5 for this module.
Community
  • Tutorials
  • Documentation
  • Forum
Open Source
  • Download
  • Github
  • Runbot
  • Translations
Services
  • Odoo.sh Hosting
  • Support
  • Upgrade
  • Custom Developments
  • Education
  • Find an Accountant
  • Find a Partner
  • Become a Partner
About us
  • Our company
  • Brand Assets
  • Contact us
  • Jobs
  • Events
  • Podcast
  • Blog
  • Customers
  • Legal • Privacy
  • Security

Odoo is a suite of open source business apps that cover all your company needs: CRM, eCommerce, accounting, inventory, point of sale, project management, etc.

Odoo's unique value proposition is to be at the same time very easy to use and fully integrated.

Website made with