Skip to main content

Simple, readable, declarative APIs for Django

Project description

Documentation Status

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'}

Optional: Implement Custom Event Hooks for Event Emission

# settings.py 
DDA_EVENT_HOOK = "my_app.hooks.custom_event_handler"

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

django_declarative_apis-0.32.0.tar.gz (53.6 kB view details)

Uploaded Source

Built Distribution

django_declarative_apis-0.32.0-py3-none-any.whl (58.2 kB view details)

Uploaded Python 3

File details

Details for the file django_declarative_apis-0.32.0.tar.gz.

File metadata

File hashes

Hashes for django_declarative_apis-0.32.0.tar.gz
Algorithm Hash digest
SHA256 262ec07ac6a3ce47e22f0c2561b07d7f2b4821b91739ade2a48cf0f5a8cd7428
MD5 493095022d7a2d2850a8d6cc0fcd22ff
BLAKE2b-256 d8b1ee5b26d8118ae81592bca0793f52ac76d6e73b22d63ede23c9026479b759

See more details on using hashes here.

File details

Details for the file django_declarative_apis-0.32.0-py3-none-any.whl.

File metadata

File hashes

Hashes for django_declarative_apis-0.32.0-py3-none-any.whl
Algorithm Hash digest
SHA256 7a39f39c785552370a5f1375b5fa9b86fa93d4e2c1d9294a80768e70ffaeb23c
MD5 6042398691dfe217360b1b1daf397b8a
BLAKE2b-256 f68c1dcab98f62c26df846bad93b0acb87c03df018d9b2d027e68333e54b159a

See more details on using hashes here.

Supported by

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