Skip to main content

Posts

Showing posts with the label CORS

Write web services using Odoo controllers

In Odoo you can write web-services for the outside world. Let's discuss how it can be done using controllers. Suppose I need a cross-domain API that will return data in JSON format. For that, we have to enable CORS and have to setup nginx reverse proxy . Example: API to send teachers data from Odoo: # -*- coding: utf-8 -*- from odoo.tools.translate import _ from odoo import http from odoo.http import request import json import sys class odoo_public_data(http.Controller):     @http.route('/get/teachers', type='http', methods=['GET'], auth="public")     def get_teachers(self, **kwargs):         teacher_model = request.env['dps.teacher']         teacher_ids = teacher_model.sudo().search([])         teacher_list = {'status': 1, 'data': []}         try:             if teacher_ids:                 for tea...