Resource centered REST API clients
Project description
Resource centered REST API clients
Ideas on how to use
Not all features stated in the following examples are implemented. This section serves only as motivation for future functionalities.
import resources
class PersonResource(resources.Resource):
class Meta:
base_endpoint = 'http://api.com/v1/persons/'
class PageResource(resources.Resource):
class Meta:
endpoints = {
'delete': 'http://api.com/v1/pages/{}/'
'filter': 'http://api.com/v1/pages/'
'get': 'http://api.com/v1/pages/{}/'
'patch': 'http://api.com/v1/pages/{}/'
'post': 'http://api.com/v1/pages/'
'put': 'http://api.com/v1/pages/'
}
owner = resources.RelatedField(
PersonResource,
source_field='owner_url', # default is owner_id
auto_follow=True, # default is False
)
comments = resources.MultipleRelatedField(
CommentResource,
source_field='comments_url',
)
# GET / single
person = Person.objects.get(pk=1)
print(person.name)
# GET / list
person_reqset = Person.objects.filter(age=18)
for person in person_reqset: # lazy request
print(person.name)
# POST
person = Person.objects.create(name='John Doe', age=18)
# PATCH
person.age = 20
person.save()
# PUT
person = Person.objects.update_or_create(name='John Doe', age=30)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
resources-0.0.1.tar.gz
(3.7 kB
view details)
File details
Details for the file resources-0.0.1.tar.gz
.
File metadata
- Download URL: resources-0.0.1.tar.gz
- Upload date:
- Size: 3.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 02547fbca96492b4a9e0a39c83bc922b8ed8f2969ee9909ceedf3609821eb900 |
|
MD5 | 29c7a0c7a69b8d6394a2eba6ba4f88f0 |
|
BLAKE2b-256 | 0d9892a43ff6fb8773590ef1edf21383a0b089a8eb0a6f18c5c2d93a8a49b864 |