-
Notifications
You must be signed in to change notification settings - Fork 18
Open
Description
Would be handy to be able to access the api like a model:
myapi = drest.api.API('http://localhost:8000/api/v1/')
myapi.auth(user='john.doe', password='XXXXXXXX')
class UserModel(drest.models.APIModel):
class Meta:
api = myapi
resource = 'users'
path = '/users/'
# New user
user = UserModel()
user.first_name = 'John'
user.last_name = 'Doe'
# POST http://localhost:8000/api/v1/users/
user.save()
### Update user
# GET http://localhost:8000/api/v1/users/?username='john.doe'
user = UserModel(username='john.doe') # exception if more than 1 result, or none
user.first_name
>>> 'john'
user.last_name
>>> 'doe'
user.first_name = 'Bob'
user.first_name
>>> 'Bob'
# PUT http://localhost:8000/api/v1/users/14/
user.save()
Metadata
Metadata
Assignees
Labels
No labels