Making a path accessible from the network
In this recipe, we'll see how to make a URL of the http://yourserver/path1/path2
form accessible to users. This can either be a web page or a path returning arbitrary data to be consumed by other programs. In the latter case, you would usually use the JSON format to consume parameters and to offer your data.
Getting ready
We'll make use of the library.book
model of Chapter 5, Application Models, so in case you haven't done so yet, grab its code to be able to follow the examples.
We want to allow any user to query the full list of books. Furthermore, we want to provide the same information to programs via a JSON request.
How to do it...
We'll need to add controllers, which go into a folder called controllers
by convention:
- Add a
controllers/main.py
file with the HTML version of our page:
from odoo import http from odoo.http import request class Main(http.Controller): @http.route('/my_module/books', type='http', auth='none') def books(self): ...