httk.serve.optimade.model.request

Classes

RawRequest

Represent an incoming OPTIMADE request from the web layer.

RequestedSlice

Represent a slice requested via dimension_slices.

ValidatedParameters

Represent validated URL query parameters of an OPTIMADE request.

ValidatedRequest

Represent the result of validating a RawRequest.

EndpointResponse

Represent an endpoint response for serialization by the web layer.

Module Contents

class httk.serve.optimade.model.request.RawRequest

Represent an incoming OPTIMADE request from the web layer.

Only baseurl and representation are mandatory; missing information is derived from representation during validation.

Parameters:
  • baseurl – Base URL used when generating response links.

  • representation – Request path and query representation.

  • relurl – Relative request URL, when supplied by the web layer.

  • querystr – Raw query string.

  • query – Parsed query parameters.

  • endpoint – Preselected endpoint, when supplied by the caller.

  • request_id – Preselected entry identifier, when supplied by the caller.

  • version – API version declared by the caller.

baseurl: str
representation: str
relurl: str | None = None
querystr: str | None = None
query: dict[str, str] | None = None
endpoint: str | None = None
request_id: str | None = None
version: str | None = None
class httk.serve.optimade.model.request.RequestedSlice

Represent a slice requested via dimension_slices.

The values are stored exactly as given (a None component means the client omitted it and the default applies). Per the OPTIMADE specification, stop is inclusive.

Parameters:
  • start – Inclusive first index, or None for the default.

  • stop – Inclusive last index, or None for the default.

  • step – Slice step, or None for the default.

start: int | None = None
stop: int | None = None
step: int | None = None
class httk.serve.optimade.model.request.ValidatedParameters

Represent validated URL query parameters of an OPTIMADE request.

Parameters:
  • response_format – Requested response format.

  • page_limit – Maximum number of entries in a page.

  • page_offset – Number of matching entries to skip.

  • response_fields – Comma-separated requested response fields.

  • filter – Raw OPTIMADE filter expression.

  • sort – Raw OPTIMADE sort expression.

  • include – Raw related-entry inclusion request.

  • as_of – Nanosecond timestamp cutoff for timestamp-capable stored sources; timestamp-disabled sources may serve current state and generic providers ignore it.

  • dimension_slices – Requested slices keyed by dimension name.

response_format: str = 'json'
page_limit: int = 50
page_offset: int = 0
response_fields: str | None = None
filter: str | None = None
sort: str | None = None
include: str | None = None
as_of: int | None = None
dimension_slices: dict[str, RequestedSlice]
as_query_dict()

Return the parameters as a URL query mapping.

Returns:

Query values with unset optional parameters omitted.

Return type:

dict[str, str]

class httk.serve.optimade.model.request.ValidatedRequest

Represent the result of validating a RawRequest.

Parameters:
  • baseurl – Base URL used when generating response links.

  • representation – Original request representation.

  • endpoint – Validated endpoint name.

  • version – Validated OPTIMADE version.

  • query – Validated query parameters.

  • url_version – Version segment present in the request URL.

  • request_id – Validated entry identifier.

  • revisions – Whether this is a stored revision request.

  • alternatives – Whether this is a stored alternative request.

  • request_immutable_id – Immutable revision identifier for a single revision request.

  • endpoint_path – Exact entry path used for collection-link generation.

  • recognized_response_fields – Requested fields known to the schema.

  • unrecognized_response_fields – Requested fields not known to the schema.

  • sort_fields – Validated sort fields and directions.

  • include_paths – Validated related-entry paths.

  • property_metadata_requested – Whether property metadata was requested.

  • partial_data_parts – Entry, identifier, and property for partial data.

  • partial_data_offset – Offset into a partial-data response.

  • warnings – Warnings collected while processing the request.

baseurl: str
representation: str
endpoint: str
version: str
query: ValidatedParameters
url_version: str | None = None
request_id: str | None = None
revisions: bool = False
alternatives: bool = False
request_immutable_id: str | None = None
endpoint_path: str | None = None
recognized_response_fields: list[str] = []
unrecognized_response_fields: list[str] = []
sort_fields: list[tuple[str, bool]] = []
include_paths: list[str] = []
property_metadata_requested: bool = False
partial_data_parts: tuple[str, str, str] | None = None
partial_data_offset: int = 0
warnings: list[dict[str, Any]] = []
class httk.serve.optimade.model.request.EndpointResponse

Represent an endpoint response for serialization by the web layer.

Either json_response (a JSON:API document) or content (a raw body) is set.

Parameters:
  • response_code – HTTP status code.

  • response_msg – HTTP status title.

  • content_type – Response media type.

  • encoding – Response character encoding.

  • content – Raw response body, when the response is not JSON.

  • json_response – JSON:API response document, when the response is JSON.

response_code: int = 200
response_msg: str = 'OK'
content_type: str = 'application/vnd.api+json'
encoding: str = 'utf-8'
content: str | None = None
json_response: dict[str, Any] | None = None