Skip to main content

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


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

Uploaded Source

Built Distribution

django_declarative_apis-0.22.1-py3-none-any.whl (74.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: django-declarative-apis-0.22.1.tar.gz
  • Upload date:
  • Size: 52.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.3.1 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.7.1

File hashes

Hashes for django-declarative-apis-0.22.1.tar.gz
Algorithm Hash digest
SHA256 9c90d787b1f8f170c5eae43dd1db36c428ba91a4eccba25cf0cd8044fc4379b5
MD5 d9b4c3c2b2ca0f934213cb4666aeb7d4
BLAKE2b-256 bb203beb21f8f6425409ab25d965bbf829aecce67c821b1cbd3ab73274de199b

See more details on using hashes here.

File details

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

File metadata

  • Download URL: django_declarative_apis-0.22.1-py3-none-any.whl
  • Upload date:
  • Size: 74.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.3.1 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.7.1

File hashes

Hashes for django_declarative_apis-0.22.1-py3-none-any.whl
Algorithm Hash digest
SHA256 23190340c99d7c0d9ef470bda1e56e33271971e9e336fb4cbf66de6a8cf4fedd
MD5 bed77dd16b31317ce091ce2761b0ff07
BLAKE2b-256 4397f1c8d0815a000cda788d697d41b08d3b8f3d82da884200ac290fcab45ee6

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