Handling requests
When a Runnable is used to handle an HTTP request, Atmo will bind that request to the Runnable. The req 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.
For Rust, these methods are available under the req module, for example req::method(). For Swift, they are prefixed with Req, for example Suborbital.ReqMethod(). For TypeScript/AssemblyScript, they are prefixed with req, for example import { reqState } from '@suborbital/suborbital'
The following namespace methods are available:

State

Returns the value from request state for the provided key:
Rust:
1
pub fn state(key: &str) -> Option<String>
Copied!
AssemblyScript:
1
function reqState(key: string): string
Copied!
Swift:
1
public func State(key: String) -> String
Copied!

Method

Returns the HTTP method for the request:
Rust:
1
pub fn method() -> String
Copied!
AssemblyScript:
1
function reqMethod(): string
Copied!
Swift:
1
public func ReqMethod() -> String
Copied!

URL

Returns the full URL of the request:
Rust:
1
pub fn url() -> String
Copied!
AssemblyScript:
1
function reqURL(): string
Copied!
Swift:
1
public func ReqURL() -> String
Copied!

ID

Returns the unique ID assigned to the request by Atmo:
Rust:
1
pub fn id() -> String
Copied!
AssemblyScript:
1
function reqID(): string
Copied!
Swift:
1
public func ReqID() -> String
Copied!

Body

Returns the full request body as bytes:
Rust:
1
pub fn body_raw() -> Vec<u8>
Copied!
AssemblyScript:
1
function reqBody(): ArrayBuffer
Copied!
Swift:
1
public func ReqBodyRaw() -> String
Copied!

Body Field

Returns the value for the provided key, if the request body is formatted as JSON:
Rust:
1
pub fn body_field(key: &str) -> String
Copied!
AssemblyScript:
1
function reqBodyField(key: string): string
Copied!
Swift:
1
public func ReqBodyField(key: String) -> String
Copied!

Header

Returns the header value for the provided key:
Rust:
1
pub fn header(key: &str) -> String
Copied!
AssemblyScript:
1
function reqHeader(key: string): string
Copied!
Swift:
1
public func ReqHeader(key: String) -> String
Copied!

URL Parameter

Returns the URL parameter for the provided key, for example /api/v1/user/:uuid
Rust:
1
pub fn url_param(key: &str) -> String
Copied!
AssemblyScript:
1
function reqURLParam(key: string): string
Copied!
Swift:
1
public func ReqParam(key: String) -> String
Copied!
Last modified 2mo ago