Generic Connector so you can easily create simple and readable classes for accessing APIs.
Project description
Base API Connector
Helps create a simple API Connector where all you have to do is define the resources and possible commands.
Instructions
Using GenericAPIConnector
First import the GenericAPIConnector class:
from base_api_connector import GenericAPIConnector
Then, define a base_api_url and resource fields like this:
class ImplementedAPIConnector(GenericAPIConnector):
base_api_url = 'http://127.0.0.1:8000/notes-backend/'
reports = APIResource(('create', 'retrieve', 'update'))
users = APIResource('all')
This will generate the following attributes when you use this class:
conn = ImplementedAPIConnector()
conn.reports.create(data)
conn.reports.retrieve(pk)
conn.reports update(pk, data)
conn.users.list()
conn.users.create(data)
conn.users.retrieve(pk)
conn.users.update(pk, data)
conn.users.delete(pk)
Using The Returned Object
The methods of GenericAPIConnector return a regular Response object from the requests module. See requests Documentation for Response for more details.
Using AsDictObject (WIP)
If you want to define how a resource looks only once, import AsDictObject:
import datetime
from base_api_connecotr import AsDictObject
class CreateUsersResourceObject(AsDictObject):
name = None # None will not pass the field in the request
created = datetime.datetime.now # use methods to set defaults like this
created_for_app = 'readme_example'
And then use it like this:
user = CreateUsersResourceObject():
user.name = 'readme user'
conn.users.create(user)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
No source distribution files available for this release.See tutorial on generating distribution archives.
Built Distribution
Close
Hashes for base_api_connector-0.1.5.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cce7d08d6819ea97250de4a9b9f0df2d5063029db1c0b53c5b24f55b4c9a6923 |
|
MD5 | 2130d90edfef4836857f760c13e917bf |
|
BLAKE2b-256 | 9c25b49938a8f3a8d92a5b6e0ff31abc66f2f3fa8b26f24ea42d0b80f732dafa |