Writing REST/JSON Applications

Nucleon makes it easy to write JSON/REST applications with relatively little code. The URL routing and view dispatching is modelled on Django’s, except that in Nucleon callables are registered directly with an app rather than being automatically loaded from a separate URL configuration module.

Views are simply methods that accept a request object as a parameter and return a response. The response is typically a structure consisting of lists, dicts, strings, etc., that will be served to the user as JSON.

The other type of response is a nucleon.http.Response subclass, which allows a wider variety of return values or response codes.

Processing Requests

Returning Responses

Nucleon includes several classes that can be used as responses, in addition to returning Python structures to be serialised as JSON. These are all based on WebOb Response:

A subclass of Response is provided as a convenience for returning a response in JSON format. This is necessary if you wish to customise the response - for example, by including different response headers, or to return a different status code.

Another convenience is the ability to raise particular exception classes which will cause Nucleon to serve standard error responses.