Controllers¶
-
class
rest_api_framework.controllers.ApiController(*args, **kwargs)[source]¶ Inherit from
WSGIWrapperimplement the base API method. Should be inherited to create your own API-
index(request)[source]¶ The root url of your ressources. Should present a list of ressources if method is GET. Should create a ressource if method is POST :param request: :type request:
werkzeug.wrappers.Requestif self.auth is set callauthentication.Authentication.check_auth()Returns: ApiController.get_list()if request.method is GET,ApiController.create()if request.method is POST
-
paginate(request)[source]¶ invoke the Pagination class if the optional pagination has been set. return the objects from the datastore using datastore.get_list :param request: :type request:
werkzeug.wrappers.Request
-
get_list(request)[source]¶ On the base implemetation only return self.paginate(request). Placeholder for pre pagination stuff.
Parameters: request ( werkzeug.wrappers.Request) –
-
unique_uri(request, identifier)[source]¶ Retreive a unique object with his URI. Act on it accordingly to the Http verb used.
Parameters: request ( werkzeug.wrappers.Request) –
-
get(request, identifier)[source]¶ Return an object or 404
Parameters: request ( werkzeug.wrappers.Request) –
-
create(request)[source]¶ Try to load the data received from json to python, format each field if a formater has been set and call the datastore for saving operation. Validation will be done on the datastore side
If creation is successfull, add the location the the headers of the response and render a 201 response with an empty body
Parameters: request ( werkzeug.wrappers.Request) –
-
-
class
rest_api_framework.controllers.Controller(*args, **kwargs)[source]¶ Controller configure the application. Set all configuration options and parameters on the Controller, the View and the Ressource
-
load_urls()[source]¶ Parameters: urls (list) – A list of tuple in the form (url(string), view(string), permitted Http verbs(list)) return a
werkzeug.routing.Mapthis method is automaticaly called by __init__ to build the
Controllerurls mapping
-
-
class
rest_api_framework.controllers.WSGIWrapper[source]¶ Base Wsgi application loader. WSGIWrapper is an abstract class. Herited by
ApiControllerit make the class callable and implement the request/response process-
wsgi_app(environ, start_response)[source]¶ instanciate a Request object, dispatch to the needed method, return a response
-
dispatch_request(request)[source]¶ Using the
werkzeug.routing.Mapconstructed byload_urls()call the view method with the request object and return the response object.
-