swh.web.api.apiresponse module

Add Link header in returned value results.

Parameters
  • request – a DRF Request object

  • rv (dict) –

    dictionary with keys:

    • headers: potential headers with ‘link-next’ and ‘link-prev’ keys

    • results: containing the result to return

  • options (dict) – the initial dict to update with result if any

Returns

dictionary with optional keys ‘link-next’ and ‘link-prev’

Return type

dict

swh.web.api.apiresponse.filter_by_fields(request, data)[source]

Extract a request parameter ‘fields’ if it exists to permit the filtering on the data dict’s keys.

If such field is not provided, returns the data as is.

swh.web.api.apiresponse.transform(rv)[source]

Transform an eventual returned value with multiple layer of information with only what’s necessary.

If the returned value rv contains the ‘results’ key, this is the associated value which is returned.

Otherwise, return the initial dict without the potential ‘headers’ key.

swh.web.api.apiresponse.make_api_response(request, data, doc_data={}, options={})[source]

Generates an API response based on the requested mimetype.

Parameters
  • request – a DRF Request object

  • data – raw data to return in the API response

  • doc_data – documentation data for HTML response

  • options – optional data that can be used to generate the response

Returns

a DRF Response a object

swh.web.api.apiresponse.error_response(request, error, doc_data)[source]

Private function to create a custom error response.

Parameters
  • request – a DRF Request object

  • error – the exception that caused the error

  • doc_data – documentation data for HTML response