File: api.rst

package info (click to toggle)
python-django-guid 3.5.2-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 664 kB
  • sloc: python: 1,267; makefile: 16
file content (62 lines) | stat: -rw-r--r-- 1,149 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
API
===

Getting started
---------------
You can either use the ``contextvar``  directly by importing it with ``django_guid.middleware import guid``,
or use the API which also logs changes. If you want to use the contextvar, please see the official Python docs.

To use the API import the functions you'd like to use:

.. code-block:: python

    from django_guid import get_guid, set_guid, clear_guid


get_guid()
----------
* **Returns**: ``str`` or ``None``, if set by Django-GUID.

Fetches the GUID.

.. code-block:: python

    guid = get_guid()

set_guid()
----------
* **Parameters**: ``guid``: ``str``

Sets the GUID to the given input.

.. code-block:: python

    set_guid('My GUID')


clear_guid()
------------
Clears the guid (sets it to ``None``)

.. code-block:: python

    clear_guid()


Example usage
-------------

.. code-block:: python

    import requests
    from django.conf import settings

    from django_guid import get_guid

    requests.get(
        url='http://localhost/api',
        headers={
            'Accept': 'application/json',
            settings.DJANGO_GUID['GUID_HEADER_NAME']: get_guid(),
        }
    )