Overview ======== API Client Factory is a python3 wrapper for REST APIs. That is, APIs that follow the pattern of using the methods as below: .. code-block:: text GET: List or Retrieve POST: Create UPDATE: Full Update PATCH: Partial Update Settings ======== To enable `django_api_client` in your project you need to add it to `INSTALLED_APPS` in your project `settings.py` file: .. code-block:: python INSTALLED_APPS = ( ... 'django_api_client', ... ) You need also to add your APIs settings using ``DJANGO_API_CLIENT`` constant. E.g: .. code-block:: python DJANGO_API_CLIENT = { 'API': { 'NAME': '', 'BASE_URL': 'https://example.com/v1', 'ENDPOINTS': [ '', '', ... ], 'AUTHENTICATION_ACCESS_TOKEN': 'TOKEN' } } - For more information on the available configurations, see at: .. toctree:: :maxdepth: 2 defaults.rst Client Methods ============== For each endpoint the client Factory will create the follow structure: Example to ``/user/users/`` - Create: .. code-block:: text usage: api_client.user.users.create(data=data) return: Response of POST of data (dict) to /user/users/ - List: .. code-block:: python usage: api_client.user.users.list() return: Response of GET to /user/users/ - Get/Retrieve/Detail: .. code-block:: python usage: api_client.user.users.get(id=123) return: Response of GET to /user/users/123/ - Update: .. code-block:: python usage: api_client.user.users.update(id=123, data=data, partial=False) return: the response of UPDATE or PATCH of data (dict) to /user/users/123/ - Delete: .. code-block:: python usage: api_client.user.users.delete(id=123) return: Response of GET to /user/users/123/ Client Usage ============ - Import the api_client_factory module and create an instance using the name of the API you set in the ``DJANGO_API_CLIENT`` constant on settings.py file: .. code-block:: python >> from django_api_client.client import api_client_factory >> api_client = api_client_factory('') >> >> result = api_client.user.users.list() >> >> # Use the result as object >> print(result.as_obj()) UserUsers( previous=None, count=1, next=None, results=[ NamelessModel(occupation=None, full_name='Admin System', image=None, cpf='', is_superuser=True, cellphone='', email='', sex=None, username='admin', birthdate='09/09/1999', logged_as='', id=1, is_temp=False, is_active=True) ] ) >> >> # Use the result as dict >> print(result.as_dict()) {'count': 1, 'next': None, 'previous': None, 'results': [{'id': 1, 'username': 'admin', 'full_name': 'Admin System', 'sex': None, 'birthdate': '09/09/1999', 'cpf': '', 'cellphone': '', 'email': '', 'image': None, 'occupation': None, 'logged_as': '', 'is_superuser': True, 'is_active': True, 'is_temp': False} ] }