Skip to main content

A library for making simple REST-like HTTP requests

Project description

httprest

httprest is a minimalistic framework for communicating with REST APIs. Its goal is to reduce a boilerplate code required to communicate with APIs.

  • It has the http package exposing an HTTP client interface. There is also a client implementation that uses urllib under the hood. So no need to use extra libraries like requests
  • It has the api.API class which may be overridden and used to make API calls

Usage

from httprest import API

class MyAPI(API):
    def operation(self):
        result = self._request("POST", "/operation/endpoint", json={...})
        if result.ok:
            print(result.json)

api = MyAPI("http://api.com")
api.operation()

Installation

pip install httprest

HTTP client

The library exposes an HTTPClient interface and provides two implementations for it:

  1. http.urllib_client.UrllibHTTPClient: the default implementation, uses the urllib library under the hood
  2. http.requests_client.RequestsHTTPClient: uses the requests library under the hood

You may also define your own HTTP client like this:

from httprest.http import HTTPClient, HTTPResponse

class MyHTTPClient(HTTPClient):
    def _request(...) -> HTTPResponse

And then you simply use it in the API client:

api = MyAPI(..., http_client=MyHTTPClient())

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

httprest-0.1.1.tar.gz (4.7 kB view hashes)

Uploaded Source

Built Distribution

httprest-0.1.1-py3-none-any.whl (6.3 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