mirror of
https://github.com/encode/django-rest-framework.git
synced 2024-09-20 19:09:03 +03:00
17
Getting to 1.0
Tom Christie edited this page 2013-05-08 01:52:39 -07:00
This page was the set of design changes that eventually lead to the 2.0 release. - It is left here for historical reasons only .
This is a rough attempt at getting the project to a throughly well documented, conceptually clean, and totally kick-ass Web API framework. Right now I think we're something like 70-80% of the way there, a lot of the hard work has been done, but there's still a little way to go before I feel like we could hit a proper 1.0 release.
Please feel free to edit and improve this page.
Stuff that needs to change
- Becomes a type of standard Django Template Response, with
.render()
method. add_header()
dropped fromView
- set headers on the response as with standard Django.
Request to extend from#128 DONEHttpRequest
.
self.DATA
,self.FILES
,self.auth
,self.method
will becomerequest.DATA
,request.FILES
,request.method
... Regular attributes on the request (eg..META
etc.) will still be available.
DONEResource.filter_response
,Resource.validate_request
->Serializer.serialize
,Deserializer.deserialize
Serializer
,Deserializer
will be decoupled fromResource
.- Method names changed to
serialize
,deserializer
- conceptually more obvious. - Views will have
.serializer
,.deserializer
DONEView
andResource
concepts separated.
- Views handle request and response objects, provide
.get()
,.post()
,.put()
... - Resources handle instances and filter arguments, provide
.read()
,.create()
,.list()
... - Views can no longer return raw objects, must return responses.
- Resources never deal with anything at HTTP level.
- Views no longer have optional
model
,form
properties that automagically create resources, if they use a resource, it must be provided using.resource
Drop#167 DONEset_script_prefix
munging.
Provide areverse
call that extends the standardreverse
, but can take the current request as an argument if an absolute URL is required.
Hooks throughout for creatingDONE.resource
,.serializer
,.renderer
etc... instances inside the View, given the classes.Drop support for unnamed args in URLs filtering as pk. Better to always be explicit in the urlconf.DONEDONEInstanceMixin
needs to disappear.DONE.CONTENT
probably needs to disappear. To confusing to have that as well as.DATA
and.FILES
.- Explorable JSON: The default JSON output could have a section for placing meta information either by default or by swapping in a new serializer. This is common in REST API's as a place to give clients things such as type information, pagination links, etc... Two approaches seem to make sense: a Tastypie compatible approach ( with a meta dict and objects list) or something like the well-regarded foursquare API (with meta, and response dicts) (@poswald)
- Support a camelCase serializer to be extra JavaScript-friendly (@poswald)
Stuff that might not be quite perfect, but will do for now
DONE [Yes it was difficult, and yes it will be very worth it - really like how the new serialization API looks].get_bound_form
will be on the Deserializer. Not perfect, and I think there might one day be something like a deserializer/renderer that handles form generation, but it's too tricky to tackle right now, and I don't think it's worth it.- Still not sure if having View.resource, View.serializer, View.renderer etc... be classes rather than instances is necessarily the best way around. Possibly too complicated to figure out until the basics are throughly sorted out. Also, it does work OK at the moment.
- Having the view instance passed to all the pluggable components is a bit hacky really, and it'd be nice to get rid of this. That won't be able to happen until the Request (3) and Response (4) changes above have happened, and even then it's still a bit tricky (eg the Documenting Renderers need to know the view name and description.) May happen before 1.0, may happen after.
Stuff that's not quite figured out
If Serializer/Deserializer is decoupled from Resource, what does a typical API definition end up looking like. Is it too verbose, and does the conceptual clarity make things more obvious to the end developer. Will we need to consider a higher level wrapper (doubt it), or having resource/serializer instances on the view, rather than classes on the view? (Would allow for more concise definitions)LOOKS GOOD - See part 3 of the tutorialAutodiscover.https://github.com/tomchristie/django-rest-framework/pull/72 is the start of this, need to figure out how that hangs together with the new stuff, and if it's flexible enough to allow various routing styles. Look to Zachary Voase's Dagny for guidance. Designed, but not yet implemented. See part 6 of the tutorial
What needs to be done
- Get cracking on 1.0 documentation. (Can start on docs, before code is complete)
- Introduction, Getting started.
- API guide.
- Views.
- Requests & Responses.
- Renderers & Parsers.
- Authentication & Permissions.
- Serializing & Deserializing.
- Resources.
- Examples. (Use existing examples.)
- Contributing and other topics.
- Gradually migrate codebase towards 1.0, in way that causes minimal disruption.
- Triage and clean up existing tickets.