Yet Another Resftul Django framework
Project description
Yard is an API oriented framework that aims to simplify the developer’s work when implementing complex API design.
Main features
Resource and API oriented
- JSON serialization
with pagination
and metadata
- Hypermedia
API documentation (Swagger support)
API discovery and browsing
Resource versioning
GEOS support
Usage
views.py
from yard import resources, fields from .models import Book from .forms import BookListForm class BooksResource(resources.Resource): class Meta: # model associated with the resource model = Book # used in the list and detail methods fields = { 'id': fields.Integer, 'title': fields.Unicode, 'publication_date': fields.Unicode, 'author': { 'age': fields.Integer, 'name': fields.Unicode } } @validate(BookListForm) def list(self, request): #GET /resource/ return Book.objects.filter(**request.form.parameters) def detail(self, request, pk): #GET /resource/:pk/ return Book.objects.get(pk=pk)
forms.py
from yard import forms class ListBook(forms.QueryForm): year = forms.IntegerField(required=False, min_value=1970, max_value=2012) title = forms.CharField(required=False) # Django's fields genre = forms.CharField(required=False) author = forms.CharField(required=False) house = forms.CharField(required=False) class Meta: lookups = { 'year': 'publication_date__year', 'title': 'title__icontains', 'genre': 'genres', 'author': 'author_id', 'house': 'publishing_house__id', } extralogic = [ AND('genre', OR('author', 'house')) ]
urls.py
from yard.api import Api from app.views import BookResource api = Api(discover=True) # Swagger support api.include( 'books', BookResource ) urlpatterns = api.urlpatterns
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
yard-framework-3.4.0.tar.gz
(21.8 kB
view hashes)
Built Distribution
Close
Hashes for yard_framework-3.4.0-py2-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a2846fa79f9bd138b589e59c72d744a115c6d54bb31bf8ef67dcf867ab4e0b67 |
|
MD5 | ad522d512ca414197cdc0c3252d0a9f2 |
|
BLAKE2b-256 | 1cc559a06645c24b2a3b761629852c13095d44c860cfcabf759fb883675917a2 |