pub struct OcpiReply<T> { /* private fields */ }server only.Expand description
An OCPI response on its way out: the envelope, plus the headers that must accompany it.
Every OCPI response carries the request and correlation IDs it was called with:
Every request SHALL contain a unique request ID, the response to this request SHALL contain the same ID.
so this type carries them rather than leaving it to each handler to remember.
Implementations§
Source§impl<T: Validate> OcpiReply<T>
impl<T: Validate> OcpiReply<T>
Sourcepub fn ok(data: T) -> Self
pub fn ok(data: T) -> Self
A 1000 Generic success reply with a payload, answered with HTTP 200.
The payload is validated on its way out, every violation is logged by JSON Pointer at
warn, and it is sent anyway. Refusing a partner’s GET because one Location in a page
of a hundred has a 46-character name turns this party’s data quality into an outage on
theirs; serving it silently is how it becomes their support ticket weeks later.
A handler that would rather refuse calls
validate itself and returns
OcpiError::Invalid.
Source§impl<T> OcpiReply<T>
impl<T> OcpiReply<T>
Sourcepub fn no_content() -> Self
pub fn no_content() -> Self
A 1000 reply with no payload, for a PUT or PATCH whose response body is unspecified.
We also advise that in such cases, platform sending the response leave the
datafield unset in the response format.
Sourcepub fn with_ids(self, ids: RequestIds) -> Self
pub fn with_ids(self, ids: RequestIds) -> Self
Attaches the request and correlation IDs of the request being answered.
Sourcepub fn with_routing(self, routing: RoutingHeaders) -> Self
pub fn with_routing(self, routing: RoutingHeaders) -> Self
Attaches the routing headers of the response.
Pass the headers already swapped for the response direction; see
RoutingHeaders::response_from.
Sourcepub fn with_headers(self, headers: HeaderMap) -> Self
pub fn with_headers(self, headers: HeaderMap) -> Self
Adds arbitrary response headers, such as the pagination trio or a Location.
Sourcepub const fn with_http_status(self, status: HttpStatus) -> Self
pub const fn with_http_status(self, status: HttpStatus) -> Self
Overrides the HTTP status.
Sourcepub fn with_message(self, message: impl Into<String>) -> Self
pub fn with_message(self, message: impl Into<String>) -> Self
Sets the status_message.
Sourcepub const fn envelope(&self) -> &OcpiResponse<T>
pub const fn envelope(&self) -> &OcpiResponse<T>
The envelope that will be sent.