ga4gh.refget.serverless.cls.http.response

Defines the Response class, which can be modified to modulate the http response sent back to the client. Response is formatted according to expected AWS SAM format.

Classes

  • Response: an HTTP response, sends back appropriate response to client

class ga4gh.refget.serverless.cls.http.response.Response

an HTTP response, sends back appropriate response to client

For each web api route, a Response object is created and modified through a chain of middleware checks. If, at the end of a middleware function, the response status code is OK (200), the next function will execute. If ever the status code is modified to an error, the response will be sent back to client without executing further processing steps.

Parameters
  • status_code (int) – response status code

  • headers (dict[str, str]) – http headers

  • body (str) – response body

  • data (dict[str, str]) – data dict accessible throughout all middleware functions

Inheritance

Inheritance diagram of Response
finalize()

Format response according to AWS lambda/API Gateway expected format

For each API route declared in an AWS SAM stack, the response must be sent back as a dict with the appropriate keys and data structures. This method formats the response object according to that format.

Returns

response information formatted according to AWS SAM

Return type

dict[str, object]

get_body()

get response body

Returns

response body

Return type

str

get_data()

get complete data dictionary

Returns

data dictionary

Return type

dict[str, str]

get_datum(key)

get the value under the specified key in data dictionary

Parameters

key (str) – data key/name

Returns

value under specified key in data dictionary

Return type

str

get_header(key)

get the value of a particular header

Parameters

key (str) – header key/name

Returns

value of specified header

Return type

str

get_headers()

get complete header dictionary

Returns

header dictionary

Return type

dict[str, str]

get_status_code()

get status code

Returns

response status code

Return type

int

put_data(key, value)

add or update a key-value pair to data dictionary

Parameters
  • key (str) – data key/name

  • value (str) – value to store under key

put_header(key, value)

add or update a key-value pair to response headers

Parameters
  • key (str) – header key/name

  • value (str) – value for this header

set_body(body)

set response body

Parameters

body (str) – string to set to response body

set_redirect_found(url)

set the response to redirect client to specified url

Parameters

url (str) – redirect url

set_status_code(status_code)

set status code

Parameters

status_code (int) – int to set to status code

update_data(new_dict)

add or update multiple keys and values to data dictionary

This method accepts a dictionary of new data, and will update the existing data dictionary with the new keys and values.

Parameters

new_dict (dict[str, str]) – dictionary to update data dictionary with

update_headers(new_dict)

add or update multiple header keys and values

This method accepts a dictionary of new headers, and will update the existing header dictionary with the new keys and values.

Parameters

new_dict (dict[str, str]) – dictionary to update headers with