Skip to main content

UA-Generic-Rest-Api

Provides basic REST API Implementation for GET, PUT, and POST, and DELETE.

Motivation

Was designed to remove similarities among REST API implementations by creating a generic REST API that classes can be extended and override for specific needs.

Features

  • GET - Implementation of GET which can single GET, batch GET, single GET with query, and GET every page on a paginated endpoint.
    • Batch gets with queries are unavailable as there is no way to give each get a unique query. Because of this the feature was not included.
  • PUT - Basic implementation of PUT which puts the payload to the given endpoint.
  • POST - Basic implementation of POST which posts the payload to the given endpoint.
  • DELETE - Basic implementation of DELETE which deletes the given endpoint.

Code Example

from ua_generic_rest_api import GenericRestApi

class SpecificRestApi(GenericRestApi):
    # Replace '...' with any other initialization arguments.
    def __init__(self, ...):
        # host, header_info, page_query, and page_tag are site specific.
        # Set them to your own values.
        super().__init__(host, header_info, page_query, page_tag=page_tag)

    # Can override GET, PUT, POST, or DELETE here.
  • host - The base url for the endpoint that is to be gotten.
  • header_info - Any information to be added to a request header such as Authorization or Content-Type.
    • Should be in the form of a dictionary, such as {"Authorization": None, "Content-Type": "text/xml"}.
  • page_query - The tag to use when querying for specific pages.
    • For example, for sites queried with the tag "?page=", page_query should be "page".
  • page_tag - The tag name of paginated endpoints to search for when getting data.
    • For sites paginated with the tag "page", page_tag should be "page".

Installation

pip install ua-generic-rest-api
pip install -r requirements.txt

Tests

  • Tests are only necessary when wanting to make changes to the module.
  • Run from root of repo
python -m unittest ua_generic_rest_api.tests.test_generic_rest_api

Credits

sterns1 EtienneThompson

License

MIT

Download files

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

Source Distribution

ua_generic_rest_api-2.1.0.tar.gz (6.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ua_generic_rest_api-2.1.0-py3-none-any.whl (7.8 kB view details)

Uploaded Python 3

File details

Details for the file ua_generic_rest_api-2.1.0.tar.gz.

File metadata

  • Download URL: ua_generic_rest_api-2.1.0.tar.gz
  • Upload date:
  • Size: 6.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.4.1 CPython/3.14.6 Linux/6.8.0-134-generic

File hashes

Hashes for ua_generic_rest_api-2.1.0.tar.gz
Algorithm Hash digest
SHA256 d71aa3c26271ef6b2be306066f19da68efbe8021662646aede9d5ff1e52fe37b
MD5 b2b2269d885124d79514d7b767d7776d
BLAKE2b-256 f971728a2bcafc63f787050424ec5bf3b0f490e8236bf10ff6681d308ffa1785

See more details on using hashes here.

File details

Details for the file ua_generic_rest_api-2.1.0-py3-none-any.whl.

File metadata

  • Download URL: ua_generic_rest_api-2.1.0-py3-none-any.whl
  • Upload date:
  • Size: 7.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.4.1 CPython/3.14.6 Linux/6.8.0-134-generic

File hashes

Hashes for ua_generic_rest_api-2.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2f0abb31cb8be0bed0691c23d5d99090ace477f247b727b4e1ccb26300bfc453
MD5 d7fa37039502608173d15f102a27b35c
BLAKE2b-256 12e06b09b99eb2a3602a349cf1e8df017f2b44fd6357049501cac7473df5e645

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 Sentry Error logging StatusPage Status page