flectra/addons/rest_api
Siddharth Bhalgami 9ca2b698d3 [IMP] Added warning message for oauth lib for REST
[ADD] Added lib in requirements.txt
2018-04-09 18:16:51 +05:30
..
controllers [ADD]REST API for flectra 2018-01-18 14:54:14 +05:30
data [ADD]REST API for flectra 2018-01-18 14:54:14 +05:30
models [IMP] Added warning message for oauth lib for REST 2018-04-09 18:16:51 +05:30
security [ADD]REST API for flectra 2018-01-18 14:54:14 +05:30
views [ADD]REST API for flectra 2018-01-18 14:54:14 +05:30
__init__.py [ADD]REST API for flectra 2018-01-18 14:54:14 +05:30
__manifest__.py [ADD]REST API for flectra 2018-01-18 14:54:14 +05:30
readme.md [ADD]REST API for flectra 2018-01-18 14:54:14 +05:30
rest_exception.py [ADD]REST API for flectra 2018-01-18 14:54:14 +05:30

REST API For Flectra

This module enable REST API in any Flectra applications/modules.

How to Use

import requests, json, pprint

data = {'username': 'admin', 'password': 'admin', 'db': 'db_flectra_base'}
s = requests.post('http://localhost:7073/api/auth/get_tokens', data=data)
content = json.loads(s.content.decode('utf-8'))
headers = {'access_token': content.get('access_token')}

GET request

p = requests.get('http://localhost:7073/api/res.partner/', headers=headers,
                 data=json.dumps({'limit': 2}))
# ***Pass optional parameter like this***
# {
#   'limit': 10, 'filters': "[('supplier','=',True),('parent_id','=', False)]",
#   'order': 'name asc', 'offset': 10
# }
print(p.content)

POST request

p = requests.post('http://localhost:7073/api/res.partner/', headers=headers,
                  data=json.dumps({
    'name':'John',
    'country_id': 105,
    'child_ids': [{'name': 'Contact', 'type':'contact'},
                  {'name': 'Invoice', 'type':'invoice'}],
    'category_id': [{'id':9}, {'id': 10}]
    }
))
print(p.content)

PUT Request

p = requests.put('http://localhost:7073/api/res.partner/68', headers=headers,
                 data=json.dumps({
    'name':'John Doe',
    'country_id': 107,
    'category_id': [{'id': 10}]
    }
))
print(p.content)

DELETE Request

p = requests.delete('http://localhost:7073/api/res.partner/68', headers=headers)
print(p.content)