A lite client for restful APIs.
Project description
restful-client-lite
A lite client for RESTFul APIs with limited features.
It provides:
restful_client_lite.APIClient
: client for eve token-auth appsrestful_client_lite.contrib.AliyunApiGatewayClient
: client for apis generated by aliyun DataService (onlyGET
is supported)
WIP.(not stable before v0.1.0)
Installation
Lastest release
pipenv:
pipenv install restful_client_lite
pip:
pip install restful_client_lite
Dev
pipenv:
pipenv install -e git+https://github.com/huandzh/restful-client-lite#egg=restful-client-lite
pip:
pip install -e git+https://github.com/huandzh/restful-client-lite#egg=restful-client-lite
Usage
Assume that we have a restful api requiring Authorization:<token>
in the header and using etag to control writes.
Create an API client:
from restful_client_lite import APIClient
api = APIClient("<api_root>", {"token": "<token>"})
Get from url:
res_get = api.get("<url>")
Post to url:
res_post = api.post("<url>", data={"<key>": "<value>"})
Patch url:
res_patch = api.patch("<url>", "<etag>", data={"<key>": "<value>"})
Patch url (fetch etag automatically in advance):
res_patch = api.patch_auto_etag("<url>", data={"<key>": "<value>"})
Delete url:
res_delete = api.delete("<url>", "<etag>")
Delete url (fetch etag automatically in advance):
res_delete = api.delete_auto_etag("<url>")
Subclass APIClient
to create custom api client:
def sign(url):
"""some function return signature"""
...
return <signed url>
class CustomAPIClient(APIClient):
"""custom api client"""
def auth_headers(self, f: Callable) -> Callable:
"""custom auth headers"""
@wraps(f)
def wrapper(*args, **kwargs):
headers = kwargs.get("headers", {}).copy()
url = args[0]
headers.update({"Signature": sign(url)})
kwargs["headers"] = headers
return f(*args, **kwargs)
3rd-party APIs
aliyun api gateway
AliyunApiGatewayClient
:
- support
GET
from aliyun-api-gateway apis (apis may generated by DataService) - handle authorization headers
- doesn't sort url params
from restful_client_lite.contrib.aliyun import AliyunApiGatewayClient
api = AliyunApiGatewayClient(
'<api_root>',
{"app_id": '<app_id>',
"app_secret": '<app_secret>'})
# make sure params in <url> are sorted
res = api.get('<url>')
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
Close
Hashes for restful-client-lite-0.0.2.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | ee232be0b9004eabaa798d4e8cc9c420a056b1ed43e29283adf15539ca9e96aa |
|
MD5 | a492e1ae7026b3c33716ed81391c1581 |
|
BLAKE2b-256 | db51871203d662d97d2e0f381a5b5fd675ecb33c457508b07647823484a339b1 |