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.
- Rust
- JavaScript/TypeScript
- AssemblyScript
- Swift
In Rust these methods are available under the req
module:
# Use the "req" module
use suborbital::req;
# Invoke the "State" method
req::state(…)
In JavaScript and TypeScript the methods live on the request
import:
import { request } from "@suborbital/runnable"
request.state(…)
In AssemblyScript all methods are prefixed with req
:
// Import then invoke "State" method
import { reqState } from '@suborbital/suborbital'
reqState(…)
In Swift these methods are prefixed with Req
:
// Invoke the "State" method
Suborbital.ReqState(…)
The following namespace methods are available:
Method
Returns the HTTP method for the request:
- Rust
- JavaScript & TypeScript
- AssemblyScript
- Swift
STATUS: STABLE
pub fn method() -> String
STATUS: BETA
request.method(): string
STATUS: BETA
function reqMethod(): string
STATUS: PREVIEW
public func ReqMethod() -> String
URL
Returns the full URL of the request:
- Rust
- JavaScript & TypeScript
- AssemblyScript
- Swift
STATUS: STABLE
pub fn url() -> String
STATUS: BETA
request.url(): string
STATUS: BETA
function reqURL(): string
STATUS: PREVIEW
public func ReqURL() -> String
ID
Returns the unique ID assigned to the request by Atmo:
- Rust
- JavaScript & TypeScript
- AssemblyScript
- Swift
STATUS: STABLE
pub fn id() -> String
STATUS: BETA
// Get request body as a JavaScript string
request.body(): string
// Get request body as raw bytes
request.bodyBytes(): Uint8Array
STATUS: BETA
function reqBody(): ArrayBuffer
STATUS: PREVIEW
public func ReqBodyRaw() -> String
Body Field
Returns the value for the provided key, if the request body is formatted as JSON:
- Rust
- JavaScript & TypeScript
- AssemblyScript
- Swift
STATUS: STABLE
pub fn body_field(key: &str) -> String
STATUS: BETA
request.bodyField(key: string): string
STATUS: BETA
function reqBodyField(key: string): string
STATUS: PREVIEW
public func ReqBodyField(key: String) -> String
Header
Returns the header value for the provided key:
- Rust
- JavaScript & TypeScript
- AssemblyScript
- Swift
STATUS: STABLE
pub fn header(key: &str) -> String
STATUS: BETA
request.header(key: string): string
STATUS: BETA
function reqHeader(key: string): string
STATUS: PREVIEW
public func ReqHeader(key: String) -> String
URL Parameter
Returns the value of a given parameter when a handler is using parametrized endpoints such as /api/v1/user/:uuid
.
- Rust
- JavaScript & TypeScript
- AssemblyScript
- Swift
STATUS: STABLE
pub fn url_param(key: &str) -> String
STATUS: BETA
request.urlParam(key: string): string
STATUS: BETA
function reqURLParam(key: string): string
STATUS: PREVIEW
public func ReqParam(key: String) -> String
State
Returns the value from request state for the provided key:
- Rust
- JavaScript & TypeScript
- AssemblyScript
- Swift
STATUS: STABLE
pub fn state(key: &str) -> Option<String>
STATUS: BETA
// Value of the state key as a JavaScript string
request.state(key: string): string
// Value of the state key as raw bytes
request.stateBytes(key: string): Uint8Array
STATUS: BETA
function reqState(key: string): string
STATUS: PREVIEW
public func State(key: String) -> String