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.33.0.tar.gz (54.1 kB view details)

Uploaded Source

Built Distribution

django_declarative_apis-0.33.0-py3-none-any.whl (58.7 kB view details)

Uploaded Python 3

File details

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

File metadata

File hashes

Hashes for django_declarative_apis-0.33.0.tar.gz
Algorithm Hash digest
SHA256 788b76a6e62bae29be5211f0dd5db3e385b7de68a921478a3d12bb92b9cca348
MD5 1cede3c83aca7ba3f8d4643dc9dc2d8d
BLAKE2b-256 ff9e926609e0902c72da04f510f5528551da12dd3439e3a636702bc60b84c93c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for django_declarative_apis-0.33.0-py3-none-any.whl
Algorithm Hash digest
SHA256 64242fb382560d2dc219b6cff5b89082e5ea523d4f47edfed02c79f5e9f794e4
MD5 f44543bad3cf52cbb0047b37c7bdd789
BLAKE2b-256 6cd8c7f8078d50de1edf4bf8352d6cad31f3ca0f1eff43cbeab863c0cd761b10

See more details on using hashes here.

Supported by

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