Object based request library.
Project description
This library is due to change in future version but is considered stable.
For now it's recommend lock this package to 0.0.1
Index
OBRequests
Object-based request library, may the force be with you. OBRequests is built using HTTPX.
Todo
- Asyncio support.
- Fully testing everything.
- Optimizing.
Using
Start by creating a class with the Request object.
class JsonPlaceHolder(Request):
pass
Then set "global" request parameters. Parameters are the same as here but with "_" (underscores).
class JsonPlaceHolder(Request):
_base_url = "https://jsonplaceholder.typicode.com"
Then add some routes, start by specifying the method in UPPER-CASE.
class JsonPlaceHolder(Request):
_base_url = "https://jsonplaceholder.typicode.com"
POST_create = "example"
GET_info = ""
Add path variables like this
class JsonPlaceHolder(Request):
_base_url = "https://jsonplaceholder.typicode.com"
POST_create = "example/{example_var}?nothing={example_var_two}"
request = JsonPlaceHolder()
resp = request.POST_create(
_example_var="Example",
_example_var_two="woo"
)
if resp.status_code == 200:
print(
resp.json()
)
You an pass parameters like this by doing this
class JsonPlaceHolder(Request):
_base_url = "https://jsonplaceholder.typicode.com"
POST_create = "example/{example_var}?nothing={example_var_two}"
request = JsonPlaceHolder()
resp = request.POST_create(
_example_var="Example",
_example_var_two="woo",
json={
"foo": "bar",
}
)
if resp.status_code == 200:
print(
resp.json()
)
Example
from OBRequests import Request
class JsonPlaceHolder(Request):
_base_url = "https://jsonplaceholder.typicode.com"
GET_posts = "posts"
GET_comment = "comments"
request = JsonPlaceHolder()
resp = request.GET_posts()
if resp.status_code == 200:
print(
resp.json()
)
resp = request.GET_comment()
if resp.status_code == 200:
print(
resp.json()
)
else:
print("Invalid url")
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.0.1.tar.gz
(3.3 kB
view hashes)
Built Distribution
OBRequests-0.0.1-py3-none-any.whl
(15.8 kB
view hashes)
Close
Hashes for OBRequests-0.0.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0c6cb82cfff08bd6c158a2eaf5151f2e640ebbec26a9fe831836b18744dd9bb2 |
|
MD5 | ee1ef710e52a80e451b6f205b6556def |
|
BLAKE2b-256 | 3cb34dff9f124d822baff0453d520c5143e6605f6474a57646c0313b50b64e8b |