Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/seebass/django-rest-hal
HAL Implementation for Django REST Framework
https://github.com/seebass/django-rest-hal
Last synced: 2 months ago
JSON representation
HAL Implementation for Django REST Framework
- Host: GitHub
- URL: https://github.com/seebass/django-rest-hal
- Owner: seebass
- Created: 2014-09-15T13:43:16.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2015-06-29T16:30:13.000Z (over 9 years ago)
- Last Synced: 2024-11-02T16:02:47.579Z (3 months ago)
- Language: Python
- Size: 247 KB
- Stars: 11
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
- starred-awesome - django-rest-hal - HAL Implementation for Django REST Framework (Python)
README
django-rest-hal
===============HAL Implementation for Django REST Framework
Includes:
* HAL Implemenentation without 'curies'
* Defining fields through url-parameter 'fields'
* Disable link generation through url-parameter 'no-links=true'For Django REST Framework 3 the have a look at these libs:
* https://github.com/seebass/drf-hal-json
* https://github.com/seebass/drf-nested-fields## Setup ##
Include the following settings in your django settings.py
'DEFAULT_MODEL_SERIALIZER_CLASS': 'django_rest_hal.serializers.HalModelSerializer',
'DEFAULT_PAGINATION_SERIALIZER_CLASS': 'django_rest_hal.serializers.HalPaginationSerializer',
'DEFAULT_PARSER_CLASSES': ('django_rest_hal.parsers.JsonHalParser',),
'DEFAULT_RENDERER_CLASSES': (
'django_rest_hal.renderers.JsonHalRenderer'
)
## Usage ##Performing REST-Requests results in following HTTP-Responses:
GET http://localhost/api/resources/1/ HTTP/1.1
Content-Type application/hal+json{
"_links": {
"self": "http://localhost/api/resources/1/",
"relatedResource": "http://localhost/api/related-resources/1/"
},
"id": 1,
"_embedded": {
"subResource": {
"_links": {
"self": "http://localhost/resources/1/sub-resources/26/"
"subSubResource": "http://localhost/resources/1/sub-resources/26/sub-sub-resources/3"
},
"id": 26,
"name": "Sub Resource 26"
}
}
}
Field customization can be declared using the URL-Query-Parameter 'fields':GET http://localhost/api/resources/1/?fields=id,subResource.fields(name,subSubResource.fields(id) HTTP/1.1
Content-Type application/hal+json{
"_links": {
"self": "http://localhost/api/resources/1/",
},
"id": 1,
"_embedded": {
"subResource": {
"_links": {
"self": "http://localhost/resources/1/sub-resources/26/"
},
"name": "Sub Resource 26"
"_embedded": {
"subSubResource": {
"_links": {
"self": "http://localhost/resources/1/sub-resources/26/sub-sub-resources/3"
}
"id": 3
}
}
}
}
}