Jump to >


class WebAPIResponse(request, obj={}, stat='ok', api_format=None, status=200, headers={}, encoders=[], encoder_kwargs={}, mimetype=None, supported_mimetypes=None)[source]

An API response, formatted for the desired file format.

property content[source]

Returns the API response content in the appropriate format.

This is an overridden version of HttpResponse._get_content that generates the resulting content when requested, rather than generating it up-front in the constructor. This is used so that the @webapi decorator can set the appropriate API format before the content is generated, but after the response is created.

class WebAPIResponsePaginated(request, queryset=None, results_key='results', prev_key='prev', next_key='next', total_results_key='total_results', start_param='start', max_results_param='max-results', default_start=0, default_max_results=25, max_results_cap=200, serialize_object_func=None, extra_data={}, *args, **kwargs)[source]

A response containing a list of results with pagination.

This accepts the following parameters to the URL:

  • start - The index of the first item (0-based index).

  • max-results - The maximum number of results to return in the request.

Subclasses can override much of the pagination behavior of this function. While the default behavior operates on a queryset and works on indexes within that queryset, subclasses can override this to work on any data and paginate in any way they see fit.


Normalizes the start value.

By default, this ensures it’s an integer no less than 0. Subclasses can override this behavior.


Returns whether there’s a previous set of results.


Returns whether there’s a next set of results.


Returns the previous index to use for ?start=


Returns the next index to use for ?start=


Returns the results for this page.


Returns the total number of results across all pages.

Subclasses can return None to prevent this field from showing up in the payload.

Returns all links used in the payload.

By default, this only includes pagination links. Subclasses can provide additional links.

build_pagination_url(full_path, start, max_results, query_parameters)[source]

Builds a URL to go to the previous or next set of results.

class WebAPIResponseError(request, err, extra_params={}, headers={}, *args, **kwargs)[source]

A general API error response.

This contains an error code and a human-readable message. Additional data can be provided through extra_params and headers.

class WebAPIResponseFormError(request, form, *args, **kwargs)[source]

An error response designed to return all errors from a form.