-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
411 additions
and
257 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Empty file.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
JSONAPI Resource | ||
================ | ||
|
||
Resources are related to Django models. | ||
Basic customization is done in Resource.Meta class. | ||
Exampele of resource declaration is shown below: | ||
|
||
.. code-block:: python | ||
from jsonapi.api import API | ||
from jsonapi.resource import Resource | ||
from django.conf import settings | ||
api = API() | ||
@api.register | ||
class UserResource(Resource): | ||
class Meta: | ||
model = settings.AUTH_USER_MODEL | ||
authenticators = [Resource.AUTHENTICATORS.SESSION] | ||
fieldnames_exclude = 'password', | ||
@api.register | ||
class AuthorResource(Resource): | ||
class Meta: | ||
model = 'testapp.Author' | ||
allowed_methods = 'GET', 'POST', 'PUT', 'DELETE' | ||
@api.register | ||
class PostWithPictureResource(Resource): | ||
class Meta: | ||
model = 'testapp.PostWithPicture' | ||
fieldnames_include = 'title_uppercased', | ||
page_size = 3 | ||
@staticmethod | ||
def dump_document_title(obj): | ||
return obj.title | ||
Available Meta parameters: | ||
|
||
+--------------------+---------------------------+-----------------------+-----------------------------------+ | ||
| Name | Type | Default | Usage | | ||
+--------------------+---------------------------+-----------------------+-----------------------------------+ | ||
| model | str | None. Need to specify | '<appname>.<modelname>' | | ||
+--------------------+---------------------------+-----------------------+-----------------------------------+ | ||
| allowed_methods | tuple | ('GET') | tuple of capitalized HTTP methods | | ||
+--------------------+---------------------------+-----------------------+-----------------------------------+ | ||
| authenticators | list | [] | [Resource.AUTHENTICATORS.SESSION] | | ||
+--------------------+---------------------------+-----------------------+-----------------------------------+ | ||
| fieldnames_include | list | [] | list of field names | | ||
+--------------------+---------------------------+-----------------------+-----------------------------------+ | ||
| fieldnames_exclude | list | [] | list of field names | | ||
+--------------------+---------------------------+-----------------------+-----------------------------------+ | ||
| page_size | int | None | integer if need pagination | | ||
+--------------------+---------------------------+-----------------------+-----------------------------------+ | ||
| form | django.forms.Form Default | ModelForm | form to use | | ||
+--------------------+---------------------------+-----------------------+-----------------------------------+ | ||
|
||
GET/POST/PUT/DELETE method kwargs | ||
--------------------------------- | ||
|
||
+---------+--------------------------------+ | ||
| name | note | | ||
+---------+--------------------------------+ | ||
| request | Django request | | ||
+---------+--------------------------------+ | ||
| ids | ids in request url, optional | | ||
+---------+--------------------------------+ | ||
|
||
Exceptions | ||
---------- | ||
|
||
.. note:: These exceptions are application specific. Than means that they are | ||
raised inside resource get/post/put/delete methods handlers but not in api. | ||
They are handled in request handler and serialized into correct response | ||
document with "errors" attribute on the top level. | ||
|
||
Error standard http://jsonapi.org/format/#errors says that every member of error | ||
object could be optional, but suggest to use some. JSONAPI defines common | ||
exceptions and allows user to raise own ones. It uses code, status, title and | ||
detail members for every exception. Sometimed members links, paths and data (not | ||
suggested by document) could be added. | ||
|
||
.. warning:: Exceptions are still in development. Codes of existing exceptions | ||
would not be changed, but titles could. | ||
|
||
+-------+--------+-----------------------------+--------------------------------+ | ||
| Code | Status | Title | Class | | ||
+-------+--------+-----------------------------+--------------------------------+ | ||
| 32000 | 400 | General JSONAPI Error | JSONAPIError | | ||
+-------+--------+-----------------------------+--------------------------------+ | ||
| 32001 | 403 | Resource Forbidden Error | JSONAPIForbiddenError | | ||
+-------+--------+-----------------------------+--------------------------------+ | ||
| 32100 | 400 | Resource Validation Error | JSONAPIResourceValidationError | | ||
+-------+--------+-----------------------------+--------------------------------+ | ||
| 32101 | 400 | Model Form Validation Error | JSONAPIFormValidationError | | ||
+-------+--------+-----------------------------+--------------------------------+ | ||
| 32102 | 400 | Model Form Save Error | JSONAPIFormSaveError | | ||
+-------+--------+-----------------------------+--------------------------------+ | ||
| 32103 | 400 | Database Integrity Error | JSONAPIIntegrityError | | ||
+-------+--------+-----------------------------+--------------------------------+ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
""" JSON:API realization.""" | ||
__version = (0, 8, 3) | ||
__version = (0, 8, 4) | ||
|
||
__version__ = version = '.'.join(map(str, __version)) | ||
__project__ = PROJECT = __name__ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.