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

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

Uploaded Source

Built Distribution

django_declarative_apis-0.31.5-py3-none-any.whl (56.7 kB view details)

Uploaded Python 3

File details

Details for the file django-declarative-apis-0.31.5.tar.gz.

File metadata

File hashes

Hashes for django-declarative-apis-0.31.5.tar.gz
Algorithm Hash digest
SHA256 c156f0f68dfd354683f2d9161c7639984c7df4b8093f5ec0e6f3ac78bd51ace1
MD5 eb9a997a7c817cb5afa4cb51aef5cbb5
BLAKE2b-256 0bc556c41dc934a19a0fd6b3ef4c7fd56729ac1b4c6d2c2297d4bdfc22b34d05

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for django_declarative_apis-0.31.5-py3-none-any.whl
Algorithm Hash digest
SHA256 6c2ec4cd92dbcdf83ab589c8c1339711ee06156c6e8f669d70c021a49c5321dc
MD5 5363bfbbe70e0e96776fcf18b2d5d143
BLAKE2b-256 7a4e019328a32242794a84f052a4b7b3ada763a92b2d2b7af2d6c7c6247de138

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