Skip to main content

REST client

Project description

A REST client - inspired by restmod for javascript.

Quick start for contributing

virtualenv -p `which python3` virtualenv
source virtualenv/bin/activate
pip install -r requirements.txt
pip install -r dev_requirements.txt
nosetests

Usage

from peace import PeaceMaker

def set_authorization_header(request):
    request.headers['Authorization'] = authorization_value
    return request

maker = PeaceMaker('http://api.example.com')
Employee = maker.make(
    'Employee',
    '/employees'
    has: {
        'user': maker.make('Company'),
    },
    intercept: set_authorization_header,
)

employees = Employee.search(_last_name='Smith')
bob = Employee.get('100')
bob.last_name = 'Smith-Jones'
bob.save()
bob.refresh()
company = bob.company
print(company.name) # prints name

Peace requires the REST API to conform to a particular structure. A JSON response should look something like this:

{
  "data": {
    "id": 100,
    "first_name": "Bob",
    "last_name": "Smith",
  },
  "links": {
    "self": {"href": "/employees/100"},
    "company": {
      "href": "/companies/5",
      "data": {
        "name": "Big Corp",
      },
    },
  },
}

Links can be followed (e.g. bob.company). Initially, the data returned in the original request will be immediately available, but if you try to access other fields that a direct load is required to make available, (i.e. were not in the original response), then a load of the linked object will be done first (e.g. GET /companies/5).

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

peace-0.0.3.tar.gz (5.3 kB view details)

Uploaded Source

File details

Details for the file peace-0.0.3.tar.gz.

File metadata

  • Download URL: peace-0.0.3.tar.gz
  • Upload date:
  • Size: 5.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for peace-0.0.3.tar.gz
Algorithm Hash digest
SHA256 a87574a3e450d4caf1b26968e1de342ecf7a5db6ae280fbdac1ccabff03ae981
MD5 c077f33a2a91d00875c1b59d0ae1aaba
BLAKE2b-256 36a68356c34bdf7a6453d748e58f3441b9d050ed01b353877de1cd5cebd1738f

See more details on using hashes here.

Supported by

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