Skip to main content

Base HTTP service client

Project description

Build Status Coverage Status Latest Version Downloads

A base HTTP service client.

By default it “demands” successful responses from API endpoints, otherwise it raises an exception.

Demands accepts all the same parameters as requests.request and extends the requests.Session class, documentation for both: Requests Developer Interface.

Written and used by the folks at Yola to support our free website builder.

HTTPServiceClient Overview

  • base class for creating service clients

  • provides flexible way of http error handling for descendants

  • HTTPServiceError raised on unexpected service response

  • Supports pre-send and post-send hooks

Usage

from demands import HTTPServiceClient

class MyService(HTTPServiceClient):
    def get_user(self, user_id):
        return self.get('/users/%s/' % user_id).json()

    def safe_get_user(self, user_id, default_user):
        response = self.get(
            '/users/%s/' % user_id,
            expected_response_codes=[404])
        return response.json() if response.is_ok else default_user


service = MyService(url='http://localhost/')
user = service.get_user(1234)

Any parameters passed to the constructor will also be used for each and every request:

service = MyService(
    url='http://localhost/',
    headers={'h1':'value'},
    auth=('username','pass'),
)

# sent with auth and both headers
user = service.get('/some-path', headers={'h2': 'kittens'})

Testing

Install development requirements:

pip install -r requirements.txt

Run the tests with:

nosetests

API documentation

To generate the documentation:

cd docs && PYTHONPATH=.. make singlehtml

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

demands-1.2.0.tar.gz (4.6 kB view details)

Uploaded Source

File details

Details for the file demands-1.2.0.tar.gz.

File metadata

  • Download URL: demands-1.2.0.tar.gz
  • Upload date:
  • Size: 4.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for demands-1.2.0.tar.gz
Algorithm Hash digest
SHA256 93c69c4a52219e4350f437de4cbfe916bc7640288387d91d927e5cfe3d6ba484
MD5 943c02618ed3d39c1b3585a6936f4871
BLAKE2b-256 21229d950df3174bb00efa08d324b4c82ab79242034b7d51b8172069a937e182

See more details on using hashes here.

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