Simple, readable, declarative APIs for Django
Project description
Overview
django-declarative-apis is a framework built on top of Django aimed at teams implementing RESTful APis. It provides a simple interface to define endpoints declaratively. Some benefits to using django-declarative-apis:
- Define endpoints declaratively
- Define model-bound and unbound resource endpoints with a consistent interface
- OAuth 1.0a authentication out of the box
- Define resource and endpoint-bound tasks, promoting modularity
- Define synchronous and asynchronous tasks (asynchronous tasks implemented with Celery)
- Separation of concerns between request body processing and business logic
Quick start
This guide is intended to demonstrate the bare minimum in order to get a django-declarative-apis project up and running. The example directory contains further examples using endpoint to model relationships, authentication and response attribute filtering.
Create django app
./manage startapp myapp
Add app to INSTALLED_APPS
INSTALLED_APPS = [
'django_declarative_apis',
'myapp',
]
Add required config
DECLARATIVE_ENDPOINT_RESOURCE_ADAPTER = 'django_declarative_apis.adapters.EndpointResource'
DECLARATIVE_ENDPOINT_AUTHENTICATION_HANDLERS = 'django_declarative_apis.authentication.oauthlib.oauth1.TwoLeggedOauth1'
myapp/urls.py
from django_declarative_apis import adapters
import myapp.resources
class NoAuth:
@staticmethod
def is_authenticated(request):
return True
urlpatterns = [
url(
r'^ping$',
adapters.resource_adapter(
get=myapp.resources.PingDefinition,
authentication=NoAuth
)
),
]
myproject/myproject/urls.py
from django.conf.urls import url, include
import myapp.urls
urlpatterns = [
url(r'^', include(myapp.urls)),
]
myapp/resources.py
from django_declarative_apis import machinery
class PingDefinition(machinery.BaseEndpointDefinition):
def is_authorized(self):
return True
@property
def resource(self):
return {'ping': 'pong'}
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
Built Distribution
Close
Hashes for django-declarative-apis-0.31.1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 140e61da323b439c4a6f25b1ad5fbd5d091940b0afb161b4726c74cd63aedd14 |
|
MD5 | 5e3d2e0e1a0fac2d46b22f4c05c040e3 |
|
BLAKE2b-256 | 1250b6bb78e47d79d290a67813232b52310402b97e2648c44b4fcf2367dfcdd4 |
Close
Hashes for django_declarative_apis-0.31.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9d756c244a75bc939964198b8edb411022c2d7be88ab4dc36eed8d0bd1b13bde |
|
MD5 | 6bbd9d2b64491149a1a5ce969df27160 |
|
BLAKE2b-256 | b06c3b9ca026d8362f0e70b551cd4a2977e2594720af56ce88a47f43d82179fd |