Skip to main content

Handling requests

When a Runnable is used to handle an HTTP request, Atmo will bind that request to the Runnable. The req or request namespace of the Runnable API can then be used to access all of the information about the request. Note if the Runnable is not being used to handle a request, then all methods in the req namespace will return empty or an error.

In Rust these methods are available under the req module:

# Use the "req" module
use suborbital::req;

# Invoke the "State" method
req::state()

The following namespace methods are available:

Method

Returns the HTTP method for the request:

STATUS: STABLE
pub fn method() -> String

URL

Returns the full URL of the request:

STATUS: STABLE
pub fn url() -> String

ID

Returns the unique ID assigned to the request by Atmo:

STATUS: STABLE
pub fn id() -> String

Body Field

Returns the value for the provided key, if the request body is formatted as JSON:

STATUS: STABLE
pub fn body_field(key: &str) -> String

Returns the header value for the provided key:

STATUS: STABLE
pub fn header(key: &str) -> String

URL Parameter

Returns the value of a given parameter when a handler is using parametrized endpoints such as /api/v1/user/:uuid.

STATUS: STABLE
pub fn url_param(key: &str) -> String

State

Returns the value from request state for the provided key:

STATUS: STABLE
pub fn state(key: &str) -> Option<String>