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. It provides a neat, familiar and easy way to control the logic for acceptable parameters in each http-GET-request.

Basic Usage

views.py

from yard import resources, forms, fields
from models import Book

class BooksResource(resources.Resource):
    # model associated with the resource (mandatory)
    model = Book
    # used in the index and show methods
    fields = {
        'id': fields.Integer,
        'title': fields.Unicode,
        'publication_date': fields.Unicode,
        'author': {
            'age': fields.Integer,
            'name': fields.Unicode
        }
    }

    class Parameters:
        year   = forms.IntegerParam( alias='publication_date__year', min=1970, max=2012 )
        title  = forms.CharParam( required=True )
        genre  = forms.CharParam( alias='genres' )
        author = forms.CharParam( alias='author__id' )
        house  = forms.CharParam( alias='publishing_house__id' )
        __logic__ = year, title, genre & (author|house)

    def list(self, request, params):
        #GET /resource/
        return Book.objects.filter( **params )

    def detail(self, request, book_id):
        #GET /resource/:id/
        return Book.objects.get( id=book_id )

    def create(self, request):
        #POST /resource/
        return 401, 'You are not authorize'

    def update(self, request, book_id):
        #PUT /resource/:id/
        ...

    def destroy(self, request, book_id):
        #DELETE /resource/:id/
        ...

urls.py

from views    import AuthorResource, BookResource
from yard.api import Api

api = Api()
api.include( 'books', BookResource )
api.include( 'authors', AuthorResource )

urlpatterns = api.urlpatterns

Main features

  • Resource and API oriented

  • Complex API logic

  • Hypermedia API

  • JSON serialization

  • API discovery

  • Pagination

  • Metadata

  • Resource versioning

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

Uploaded Source

Built Distribution

yard_framework-2.2.0-py2-none-any.whl (33.6 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