Add a WebAPIResource class for creating more RESTful APIs.

Review Request #1528 — Created April 21, 2010 and submitted

Information

Djblets
master

Reviewers

Add a WebAPIResource class for creating more RESTful APIs.

This introduces a new class for easily creating RESTful URL resources
that can handle standard HTTP methods and return meaningful data in a
nicely constructed hierarchy.

By using WebAPIResource, a site can offer a very clean set of URLs to
work with any object.

There's a lot to this object, but it's all covered in the extensive
documentation in webapi/resources.py.

Review Board will be using this for its new more RESTful API.

There's more I want to do for this soon, such as automatic documentation
generation and proper mimetype detection, but I wanted to get this in
as a base first.
Tested this with my upcoming Review Board change for the web API. 
chipx86
chipx86
david
  1. 
      
  2. djblets/webapi/core.py (Diff revision 3)
     
     
    Why not just have headers default to {}?
    1. I think the reason I did it was to not add stuff to the passed in headers dictionary in the case of it being the default {} (as those values would be used the next time), but I really should just copy the dictionary anyway, since it is being modified.
  3. djblets/webapi/decorators.py (Diff revision 3)
     
     
    Will 'method' or 'callback' ever be in supported_fields? If not, you can get rid of the check above.
    1. These are actually special parameters that are handled by the Djblets webapi code. They should never be in supported_fields, but we want to pretend they're valid anyway. I don't know if you meant the check that you commented on or the previous one, but I don't think I can get rid of either and have this work.
  4. djblets/webapi/resources.py (Diff revision 3)
     
     
    I assume you meant "Resources"?
  5. djblets/webapi/resources.py (Diff revision 3)
     
     
     
    Dostring?
  6. 
      
chipx86
Review request changed
Change Summary:
* Cleaned up get_href and made it require a request parameter. It should always get passed one, so there's no reason for it to be optional.
* Renamed get_links_for_resources to get_links.
* Added documentation for get_links.
* Resource names are now expected to use '_' instead of '-', with normalization to '-' happening for uri_name.
* Moved the encoders to encoders.py, and brought back the original code for BasicAPIEncoder, in order to maintain backwards-compatibility.
* Fixed the checks for determining when to call get_list in order to work with resources that don't have a Model, but do have a list of child resources.
* Check for "_method" in the decorator instead of "method", since it's been renamed.
* The headers dictionary in WebAPIResponseError now defaults to {} and is properly copied before modification in order to prevent data leaking into the passed in dictionary.
david
  1. 
      
  2.