Django JSON API Made Simple
No more forcing your JSON to be bound to models.
This is a JSON api framework, the way it should be.
- Flexible / Dynamic
The API framework uses Django Forms, so no more bull trying to validate input a certain way.
# !!! Get to the code !!!
How about this?
First: `pip install django-jsonapi`, ok now:
from djsonapi import api, serial
return serial.serialize_model(obj, fields=("name", "email", "last_login", "date_joined"))
return serial.serialize_model(obj, fields=("name", "date_joined"))
@api.require_method("GET", "POST") # passes post/put down, 405's if method is incorrect
@api.post_form(forms.UserUpdateForm) # validates post/put data with form
def profile(request, form):
# form is guaranteed to be valid here
user = form.save()
user = request.user
data = serial.serialize(user, mode="current_user")
return api.ok(message="Hello World!", user=user)
The response could look like:
"message": "Hello World!",
"name": "Evan Leis",
For more code, see the example app.
**Important: make sure your serializers get loaded.**
Easiest way to do this is put them in a file called serial.py and in your app's `__init__.py`, load via
from myproj.myapp.serial import *
Methods for serializing objects into dicts, and dicts into JSON.
Methods for returning HttpResponses with JSON data.
The MIT License (MIT)
Copyright (c) 2014 Evan Leis
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.