Skip to main content

A Django app to request external API endpoints.

Project description

Polls is a Django app to reach external APIs by mirroring DRF architecture.

Quick start

  1. Add “generic_api” to your INSTALLED_APPS setting like this:

    INSTALLED_APPS = [
        ...
        'generic_api',
    ]
  2. Create your session class that will hold the authentication and the base URL:

    from generic_api.session import ConstanceSession

    class MySession(ConstanceSession):

    base_url = ‘https://baseurl/v1/’ constance_key = ‘MY_TOKEN’

  3. Create the client that will perform the queries:

    from generic_api.errors_handler import HttpErrorsHandler from generic_api.generics import GenericClient

    class MyClient(GenericClient):

    session_class = MySession errors_handler_class = HttpErrorsHandler

  4. Create the serializers for requests and responses:

    class MyRequestSerializer(serializers.Serializer):

    name = serializers.CharField()

    class MyResponseSerializer(serializers.Serializer):

    id = serializer.IntegerField()

Those are used to valid the request performed and the response received. If allows to detect quickly if something changed on the remote API

  1. Create your endpoint:

    from generic_api.endpoints import GetEndpoint

    class MyEndpointEndpoint(GetEndpoint):

    endpoint_url = ‘search/by_name’ # This can take argument, like endpoint_url: ‘{}/list’ client_class = MyClient response_entity_class = MyResponseSerializer request_entity_class = MyRequestSerializer

If your serializer are ModelSerializer, the object can be saved.

  1. Use the endpoint:

    endpoint = MyEndpoint()

    data = endpoint.get(**kwargs) data = data.save()

This project is available on GitHub: https://github.com/guestready/generic_api

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

generic-api-0.1.0.tar.gz (8.1 kB view details)

Uploaded Source

File details

Details for the file generic-api-0.1.0.tar.gz.

File metadata

  • Download URL: generic-api-0.1.0.tar.gz
  • Upload date:
  • Size: 8.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.23.0 setuptools/46.0.0 requests-toolbelt/0.9.1 tqdm/4.53.0 CPython/3.6.9

File hashes

Hashes for generic-api-0.1.0.tar.gz
Algorithm Hash digest
SHA256 f09a186930bc770222ccee8a1d95f75ceb0993dda8538eb297fa66c77af359b5
MD5 9e35b395e4131ddd1e1bf4e6a11c500a
BLAKE2b-256 d604e8f2ed86405027eda1856cb716aeda521bd249b1ed351ae7549465473db7

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page