swh.web.api.apiresponse module#
- swh.web.api.apiresponse.compute_link_header(rv: Dict[str, Any], options: Dict[str, Any]) Dict[str, Any][source]#
- Add Link header in returned value results. - Parameters:
- Returns:
- dictionary with optional keys ‘link-next’ and ‘link-prev’ 
- Return type:
 
- swh.web.api.apiresponse.filter_by_fields(request: Request, data: Dict[str, Any]) Dict[str, Any][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: Dict[str, Any]) Dict[str, Any][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: Request, data: Dict[str, Any], doc_data: Dict[str, Any] | None = None, options: Dict[str, Any] | None = None) HttpResponse[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: Request, exception: Exception, doc_data: Dict[str, Any]) HttpResponse[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