Develop your own high level REST APIs for Odoo thanks to this addon.
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
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.
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.
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'
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
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
The HTTP GET 'http://my_odoo/my_services_api/ping' will be dispatched to the method PingService.search
- _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).
- Licence changed from AGPL-3 to LGPL-3
- Fix issue when rendering the jsonapi documentation if no documentation is provided on a method part of the REST api.
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 smashing it by providing a detailed and welcomed feedback.
Do not contact contributors directly about support or help with technical issues.
This module is maintained by the OCA.
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.
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.
Once the user has seen at least one product this snippet will be visible.