https://github.com/russellluo/crest
A simple REST client for Python.
https://github.com/russellluo/crest
Last synced: over 1 year ago
JSON representation
A simple REST client for Python.
- Host: GitHub
- URL: https://github.com/russellluo/crest
- Owner: RussellLuo
- Created: 2014-11-24T13:59:08.000Z (over 11 years ago)
- Default Branch: master
- Last Pushed: 2015-02-27T08:56:56.000Z (over 11 years ago)
- Last Synced: 2025-03-22T14:41:31.159Z (over 1 year ago)
- Language: Python
- Homepage:
- Size: 176 KB
- Stars: 8
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
Crest
=====
A simple REST client for Python.
Installation
------------
Install `Crest` with `pip`:
$ pip install python-crest
Install development version from `GitHub`:
$ git clone https://github.com/RussellLuo/crest.git
$ cd crest
$ python setup.py install
Getting Started
---------------
Create an API resource:
from crest import Resource
# a simple API
api = Resource('http://example.com/api')
# an API required authentication
api = Resource('http://example.com/api', auth=('username', 'password'))
# GET http://example.com/api
api.get()
Get a resource within the API:
users = api.users
# GET http://example.com/api/users
users.get()
# GET http://example.com/api/users?name=russell
users.get(params={'name': 'russell'})
# POST http://example.com/api/users (payload: {"name": "russell"})
users.post(json={'name': 'russell'})
# GET http://example.com/api/users/1
users[1].get()
# PATCH http://example.com/api/users/1 (payload: {"name": "russell"})
users[1].patch(json={'name': 'russell'})
Get a sub resource of `users`:
operations = users[1].operations
# GET http://example.com/api/users/1/operations
operations.get()
# GET http://example.com/api/users/1/operations/1
operations[1].get()
Thanks
------
`Crest` is based on kennethreitz's [requests][1], and is inspired by adnam's [resources][2]. Thank you guys!
[1]: https://github.com/kennethreitz/requests
[2]: https://github.com/adnam/resources