Skip to main content

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


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)

Uploaded Source

Built Distribution

OBRequests-0.0.1-py3-none-any.whl (15.8 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page