Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
9e97015
[feature] REST API for main controller features #379
ManishShah120 Feb 13, 2021
5ead323
[docs] Added the documentation for the rest API feature
ManishShah120 Mar 26, 2021
b04bd83
[tests] Tests for main controller API feature
ManishShah120 Mar 27, 2021
38f4816
[api] Improvements and Handled Corner Cases
ManishShah120 Apr 3, 2021
9d779db
[api] Enhancements and Improvemesnts
ManishShah120 Apr 6, 2021
e45685f
[api] Improvements
ManishShah120 Apr 9, 2021
9c25048
[fix] Return all the objects to admin
ManishShah120 Apr 12, 2021
fb44b20
[fix] Minor code enhancement
ManishShah120 Apr 15, 2021
6d5984f
[fix] Restrict who can set Organization=None
ManishShah120 Apr 20, 2021
cd2ca57
[fix] Minor bug fix related to required Templates
ManishShah120 Apr 20, 2021
22ad25b
[fix] Fixed the representation of JSON fields
ManishShah120 Apr 24, 2021
3cdd17d
[api] Improvements of corner casses
ManishShah120 Apr 27, 2021
2ea8207
[api] Fixed transalatable strings and readonly fields
ManishShah120 Apr 30, 2021
b3bbdd1
[api] Added config field in the device list endpoint
ManishShah120 Apr 30, 2021
8caa48f
[api] Reverted the last_ip, management_ip to prev representation
ManishShah120 Apr 30, 2021
846d6ce
[api] Simplified `create` function of `DeviceListSerializer`
ManishShah120 May 1, 2021
af7b407
[api] Added ` vpn` field in `TemplateSerializer`
ManishShah120 May 1, 2021
4fde2f8
[api] Code quality improvements
ManishShah120 May 2, 2021
48b7697
[api] Removed white trailing spaces
ManishShah120 May 2, 2021
f5154dc
[api] Handled a corner case related to vpn type template
ManishShah120 May 2, 2021
6e4cf9c
[api] Minor Code improvements
ManishShah120 May 2, 2021
a005738
[api] Fixed variable name issue
ManishShah120 May 4, 2021
06b183f
[api] Fixed config representation for DeviceList endpoint
ManishShah120 May 4, 2021
efebb91
[api] Fixed a validation issue in template Serilaizer
ManishShah120 May 5, 2021
c592b3e
[api] Simplified Template filtering for Device Serializer
ManishShah120 May 6, 2021
718e414
[api] Added tests for template creation of VPN type
ManishShah120 May 7, 2021
4eacd3c
[api] Added `include_shared` and added new tests for post request wit…
ManishShah120 May 7, 2021
3eed885
[api] Minor improvements
ManishShah120 May 8, 2021
15405eb
[api] Added Extensibility feat for the config api
ManishShah120 May 8, 2021
7e1d9ca
[chores] Fix field name while validation in template serializer
ManishShah120 May 10, 2021
c742290
[tests] Fixed build failing issue
ManishShah120 May 11, 2021
28f1622
[chores] Point screenshots to master
nemesifier May 12, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
245 changes: 245 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -593,6 +593,251 @@ For example, if we want to change the verbose name to "Hotspot", we could write:

OPENWISP_CONTROLLER_DEVICE_VERBOSE_NAME = ('Hotspot', 'Hotspots')

``OPENWISP_CONTROLLER_API``
~~~~~~~~~~~~~~~~~~~~~~~~~~~

+--------------+-----------+
| **type**: | ``bool`` |
+--------------+-----------+
| **default**: | ``True`` |
+--------------+-----------+

Indicates whether the API for Openwisp Controller is enabled or not.
To disable the API by default add `OPENWISP_CONTROLLER_API = False` in `settings.py` file.

REST API
--------

Live documentation
~~~~~~~~~~~~~~~~~~

.. image:: https://raw.githubusercontent.com/openwisp/openwisp-controller/master/docs/live-docu-api.png

A general live API documentation (following the OpenAPI specification) at ``/api/v1/docs/``.

Browsable web interface
~~~~~~~~~~~~~~~~~~~~~~~

.. image:: https://raw.githubusercontent.com/openwisp/openwisp-controller/master/docs/browsable-api-ui.png

Additionally, opening any of the endpoints `listed below <#list-of-endpoints>`_
directly in the browser will show the `browsable API interface of Django-REST-Framework
<https://www.django-rest-framework.org/topics/browsable-api/>`_,
which makes it even easier to find out the details of each endpoint.

Authentication
~~~~~~~~~~~~~~

See openwisp-users: `authenticating with the user token
<https://github.com/openwisp/openwisp-users#authenticating-with-the-user-token>`_.

When browsing the API via the `Live documentation <#live-documentation>`_
or the `Browsable web page <#browsable-web-interface>`_, you can also use
the session authentication by logging in the django admin.

Pagination
~~~~~~~~~~

All *list* endpoints support the ``page_size`` parameter that allows paginating
the results in conjunction with the ``page`` parameter.

.. code-block:: text

GET /api/v1/controller/template/?page_size=10
GET /api/v1/controller/template/?page_size=10&page=2

List of endpoints
~~~~~~~~~~~~~~~~~

Since the detailed explanation is contained in the `Live documentation <#live-documentation>`_
and in the `Browsable web page <#browsable-web-interface>`_ of each point,
here we'll provide just a list of the available endpoints,
for further information please open the URL of the endpoint in your browser.

List devices
^^^^^^^^^^^^

.. code-block:: text

GET /api/v1/controller/device/

Create device
^^^^^^^^^^^^^

.. code-block:: text

POST /api/v1/controller/device/

Get device detail
^^^^^^^^^^^^^^^^^

.. code-block:: text

GET /api/v1/controller/device/{pk}/

Download device configuration
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

.. code-block:: text

GET /api/v1/controller/device/{pk}/configuration/

The above endpoint triggers the download of a ``tar.gz`` file containing the generated configuration for that specific device.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

try to make sure lines are not longer than 70/80 characters as in the rest of the text please (applies to all other lines as well).


Change details of device
^^^^^^^^^^^^^^^^^^^^^^^^

.. code-block:: text

PUT /api/v1/controller/device/{pk}/

Patch details of device
^^^^^^^^^^^^^^^^^^^^^^^

.. code-block:: text

PATCH /api/v1/controller/device/{pk}/

**Note**: To assign, unassign, and change the order of the assigned templates add,
remove, and change the order of the ``{pk}`` of the templates under the ``config`` field in the JSON response respectively.
Moreover, you can also select and unselect templates in the HTML Form of the Browsable API.

The required template(s) from the organization(s) of the device will added automatically
to the ``config`` and cannot be removed.

**Example usage**: For assigning template(s) add the/their {pk} to the config of a device,

.. code-block:: shell

echo '{"config":{"templates": ["4791fa4c-2cef-4f42-8bb4-c86018d71bd3"]}}' | \
http PATCH http://127.0.0.1:8000/api/v1/controller/device/76b7d9cc-4ffd-4a43-b1b0-8f8befd1a7c0/ \
"Authorization: Bearer 9b5e40da02d107cfdb9d6b69b26dc00332ec2fbc"

**Example usage**: For removing assigned templates, simply remove the/their {pk} from the config of a device,

.. code-block:: shell

echo '{"config":{"templates": []}}' | \
http PATCH http://127.0.0.1:8000/api/v1/controller/device/76b7d9cc-4ffd-4a43-b1b0-8f8befd1a7c0/ \
"Authorization: Bearer 9b5e40da02d107cfdb9d6b69b26dc00332ec2fbc"

**Example usage**: For reordering the templates simply change their order from the config of a device,

.. code-block:: shell

echo '{"config":{"templates": ["c5bbc697-170e-44bc-8eb7-b944b55ee88f","4791fa4c-2cef-4f42-8bb4-c86018d71bd3"]}}' | \
http PATCH http://127.0.0.1:8000/api/v1/controller/device/76b7d9cc-4ffd-4a43-b1b0-8f8befd1a7c0/ \
"Authorization: Bearer 9b5e40da02d107cfdb9d6b69b26dc00332ec2fbc"

Delete device
^^^^^^^^^^^^^

.. code-block:: text

DELETE /api/v1/controller/device/{pk}/

List templates
^^^^^^^^^^^^^^

.. code-block:: text

GET /api/v1/controller/template/

Create template
^^^^^^^^^^^^^^^

.. code-block:: text

POST /api/v1/controller/template/

Get template detail
^^^^^^^^^^^^^^^^^^^

.. code-block:: text

GET /api/v1/controller/template/{pk}/

Download template configuration
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

.. code-block:: text

GET /api/v1/controller/template/{pk}/configuration/

The above endpoint triggers the download of a ``tar.gz`` file containing the generated configuration for that specific template.

Change details of template
^^^^^^^^^^^^^^^^^^^^^^^^^^

.. code-block:: text

PUT /api/v1/controller/template/{pk}/

Patch details of template
^^^^^^^^^^^^^^^^^^^^^^^^^

.. code-block:: text

PATCH /api/v1/controller/template/{pk}/

Delete template
^^^^^^^^^^^^^^^

.. code-block:: text

DELETE /api/v1/controller/template/{pk}/

List VPNs
^^^^^^^^^

.. code-block:: text

GET /api/v1/controller/vpn/

Create VPN
^^^^^^^^^^

.. code-block:: text

POST /api/v1/controller/vpn/

Get VPN detail
^^^^^^^^^^^^^^

.. code-block:: text

GET /api/v1/controller/vpn/{pk}/

Download VPN configuration
^^^^^^^^^^^^^^^^^^^^^^^^^^

.. code-block:: text

GET /api/v1/controller/vpn/{pk}/configuration/

The above endpoint triggers the download of a ``tar.gz`` file containing the generated configuration for that specific VPN.

Change details of VPN
^^^^^^^^^^^^^^^^^^^^^

.. code-block:: text

PUT /api/v1/controller/vpn/{pk}/

Patch details of VPN
^^^^^^^^^^^^^^^^^^^^

.. code-block:: text

PATCH /api/v1/controller/vpn/{pk}/

Delete VPN
^^^^^^^^^^

.. code-block:: text

DELETE /api/v1/controller/vpn/{pk}/

Default Alerts / Notifications
------------------------------

Expand Down
Binary file added docs/browsable-api-ui.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/live-docu-api.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file.
Loading