Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/salesforce/django-declarative-apis
Simple, readable, declarative APIs for Django
https://github.com/salesforce/django-declarative-apis
django python rest-api
Last synced: 6 days ago
JSON representation
Simple, readable, declarative APIs for Django
- Host: GitHub
- URL: https://github.com/salesforce/django-declarative-apis
- Owner: salesforce
- License: bsd-3-clause
- Created: 2019-07-12T16:50:10.000Z (over 5 years ago)
- Default Branch: main
- Last Pushed: 2024-06-21T15:52:10.000Z (5 months ago)
- Last Synced: 2024-06-23T07:04:28.620Z (5 months ago)
- Topics: django, python, rest-api
- Language: Python
- Homepage: https://django-declarative-apis.readthedocs.io/en/stable/
- Size: 540 KB
- Stars: 26
- Watchers: 9
- Forks: 14
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: contributing.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
- Codeowners: CODEOWNERS
- Security: SECURITY.md
- Authors: AUTHORS
Awesome Lists containing this project
README
[![Documentation Status](https://readthedocs.org/projects/django-declarative-apis/badge/?version=stable)](https://django-declarative-apis.readthedocs.io/en/stable/?badge=stable)
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 logicQuick 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
-----------------``` sourceCode
./manage startapp myapp
```Add app to INSTALLED\_APPS
--------------------------``` python
INSTALLED_APPS = [
'django_declarative_apis',
'myapp',
]
```Add required config
-------------------``` python
DECLARATIVE_ENDPOINT_RESOURCE_ADAPTER = 'django_declarative_apis.adapters.EndpointResource'
DECLARATIVE_ENDPOINT_AUTHENTICATION_HANDLERS = 'django_declarative_apis.authentication.oauthlib.oauth1.TwoLeggedOauth1'
```myapp/urls.py
-------------``` python
from django_declarative_apis import adapters
import myapp.resourcesclass NoAuth:
@staticmethod
def is_authenticated(request):
return Trueurlpatterns = [
url(
r'^ping$',
adapters.resource_adapter(
get=myapp.resources.PingDefinition,
authentication=NoAuth
)
),
]
```myproject/myproject/urls.py
---------------------------``` python
from django.conf.urls import url, include
import myapp.urlsurlpatterns = [
url(r'^', include(myapp.urls)),
]
```myapp/resources.py
------------------``` python
from django_declarative_apis import machineryclass PingDefinition(machinery.BaseEndpointDefinition):
def is_authorized(self):
return True@property
def resource(self):
return {'ping': 'pong'}
```