Files
tryton/trytond/doc/topics/user_application.rst
T

86 lines
2.5 KiB
ReStructuredText
Raw Normal View History

2016-09-27 11:56:19 +02:00
.. _topics-user_application:
================
User Application
================
Tryton provides a way to connect URL rules to an callable endpoint using the
decorator method ``route`` of the ``trytond.wsgi.app`` instance. This
allows you to define a custom API based on HTTP that can be used to create a
specific user application.
2016-09-27 11:56:19 +02:00
The decorator takes as first parameter a string which follow the `Rule
Format`_ of Werkzeug and as second parameter sequence of HTTP methods.
Example::
from trytond.wsgi import app
2016-09-27 11:56:19 +02:00
@app.route('/hello', methods=['GET'])
def hello(request):
return 'Hello world'
.. _Rule Format: http://werkzeug.pocoo.org/docs/latest/routing/#rule-format
2019-03-30 17:33:20 +01:00
The following converter is added by Tryton:
2022-03-27 16:06:09 +02:00
``base64``
This converter accepts any Base64_ string and transforms it into its
corresponding bytes value.
2019-03-30 17:33:20 +01:00
.. _Base64: https://en.wikipedia.org/wiki/Base64
Tryton also provides some wrappers in ``trytond.protocols.wrappers`` to ease the
2016-09-27 11:56:19 +02:00
creation of such route.
2022-03-27 16:06:09 +02:00
``set_max_request_size(size)``
Change the default limit of the request to the size in bytes.
2017-09-03 11:32:17 +02:00
2022-03-27 16:06:09 +02:00
``allow_null_origin``
Allow requests which have their ``Origin`` set to ``null``.
2021-03-07 10:01:20 +01:00
2022-03-27 16:06:09 +02:00
``with_pool``
Take the first parameter as database name and replace it by the
corresponding instance of the :ref:`Pool <ref-pool>`.
2016-09-27 11:56:19 +02:00
2022-03-27 16:06:09 +02:00
``with_transaction([readonly])``
2022-04-06 18:19:49 +02:00
Start a :class:`~trytond.transaction.Transaction` using the :ref:`Pool
<ref-pool>` from ``with_pool``.
2022-03-27 16:06:09 +02:00
If ``readonly`` is not set, the transaction will not be readonly for
``POST``, ``PUT``, ``DELETE`` and ``PATCH`` methods and readonly for all
others.
2016-09-27 11:56:19 +02:00
2022-03-27 16:06:09 +02:00
``user_application(name[, json])``
Set the :attr:`~trytond.transaction.Transaction.user` from the
``Authorization`` header using the type ``bearer`` and a valid key for the
named user application.
2016-09-27 11:56:19 +02:00
User Application Key
====================
Tryton also provides a easy way to manage access to user application using
keys per named application.
A key is created with a ``POST`` request on the ``URL``
``/<database_name>/user/application/`` which returns the key. The request must
2022-03-27 16:06:09 +02:00
contain as data a JSON object with the keys:
2016-09-27 11:56:19 +02:00
2022-03-27 16:06:09 +02:00
``user``
The user login.
2016-09-27 11:56:19 +02:00
2022-03-27 16:06:09 +02:00
``application``
The name of the application.
2016-09-27 11:56:19 +02:00
After the creation, the key must be validated by the user from the preferences
of a Tryton client.
A key can be deleted with a ``DELETE`` request on the same ``URL``. The request
2022-03-27 16:06:09 +02:00
must contain as data a JSON object with the keys:
2016-09-27 11:56:19 +02:00
2022-03-27 16:06:09 +02:00
``user``
The user login.
2016-09-27 11:56:19 +02:00
2022-03-27 16:06:09 +02:00
``key``
The key to delete.
2016-09-27 11:56:19 +02:00
2022-03-27 16:06:09 +02:00
``application``
The name of the application of the key.