Controllers

class rest_api_framework.controllers.ApiController(*args, **kwargs)[source]

Inherit from WSGIWrapper implement 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.Request if self.auth is set call authentication.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) –
update_list(request)[source]

Try to mass update the data.

update(request, identifier)[source]

Try to retreive the object identified by the identifier. Try to load the incomming data from json to python.

Call the datastore for update.

If update is successfull, return the object updated with a status of 200

Parameters:request (werkzeug.wrappers.Request) –
delete(request, identifier)[source]

try to retreive the object from the datastore (will raise a NotFound Error if object does not exist) call the delete

method on the datastore.

return a response with a status code of 204 (NO CONTENT)

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.Map

this method is automaticaly called by __init__ to build the Controller urls mapping

make_options(options)[source]

Make options enable Pagination, Authentication, Authorization, RateLimit and all other options an application need.

class rest_api_framework.controllers.WSGIWrapper[source]

Base Wsgi application loader. WSGIWrapper is an abstract class. Herited by ApiController it 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.Map constructed by load_urls() call the view method with the request object and return the response object.

class rest_api_framework.controllers.AutoDocGenerator(apps)[source]

Auto generate a documentation endpoint for each endpoints registered.

schema(request)[source]

Generate the schema url of each endpoints

ressource_schema(request, ressource)[source]
Generate the main endpoint of schema. Return the list of all
print app.datastore.modelendpoints available