Skip to main content

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 (mandatory)
        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


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.2.0.tar.gz (21.4 kB view hashes)

Uploaded Source

Built Distribution

yard_framework-3.2.0-py2-none-any.whl (34.3 kB view hashes)

Uploaded Python 2

Supported by

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