Object based request library.
Project description
About
OBRequests is a object-based request library for HTTP built on top of HTTPX. It's feature rich, easy to use & fast. Currently supports all major request methods & also includes asyncio support.
Install
- Pypi:
pip3 install OBRequests
- Git:
pip3 install git+https://github.com/WardPearce/OBRequests.git
So how does it work?
You can read the full documentation here and find more detailed examples in the tests folder.
Here is a basic look at OBRequests.
# 1st thing 1st, lets import all the modules we'll need.
from OBRequests import Request, Methods
from OBRequests.method import Get
from OBRequests.response import Json
# Now lets create a request object.
typicode_api = Request(
# Here we're setting the base url.
"https://jsonplaceholder.typicode.com",
# Here we're setting the client to synchronous and not asynchronous.
awaiting=False,
# Here we're setting a global response action.
# Basically saying if we get the status code 200
# we want json returned, if a status code doesn't match
# the resp_actions then well just return the HTTPX response
# object.
resp_actions={
200: Json
},
# jsonplaceholder doesn't need authorization
# but this is an example on how to have some
# global headers, any httpx.Client parameter
# can be passed here.
headers={
"Authorization": "api_key"
},
# Now lets make our 1st route,
# routes are identified but a double underscore
# e.g. '__'
# All routes expect the Methods object.
__comments=Methods(
# Here we're passing the prefix
# to attach to the end of the base
# URL.
"comments/{id}",
[
# Here we can list all the
# different request methods
# this route supports.
Get(
# Lets set a default value for
# id.
_id=None,
# Now lets raise a custom
# expectation if we 404.
resp_exceptions={
404: NotImplemented
}
)
]
)
)
# Now lets make a request.
try:
json = typicode_api.comments.get(
# Here we are setting
# the path parameter to 1.
_id=1
)
except NotImplemented:
# Here is where we can
# catch that 404 expectation we set.
pass
else:
print(json)
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 Distribution
OBRequests-0.2.0.tar.gz
(5.7 kB
view hashes)
Built Distribution
OBRequests-0.2.0-py3-none-any.whl
(20.8 kB
view hashes)
Close
Hashes for OBRequests-0.2.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e16794a4df489c741a20454a50d5a0180584804269bd28841ce2fa5a564dbc56 |
|
MD5 | 0a125ef5b27ca287b0a8d4de7108543e |
|
BLAKE2b-256 | 1546e4fb9544aca358d543d2d5f75182c9947385f347be601f07067e256f2490 |