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.
- Rust
- 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 TypeScript/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
- AssemblyScript 🧪
- Swift 🧪
pub fn method() -> String
function reqMethod(): string
public func ReqMethod() -> String
URL​
Returns the full URL of the request:
- Rust
- AssemblyScript 🧪
- Swift 🧪
pub fn url() -> String
function reqURL(): string
public func ReqURL() -> String
ID​
Returns the unique ID assigned to the request by Atmo:
- Rust
- AssemblyScript 🧪
- Swift 🧪
pub fn id() -> String
function reqID(): string
public func ReqID() -> String
Body​
Returns the full request body as bytes:
- Rust
- AssemblyScript 🧪
- Swift 🧪
pub fn body_raw() -> Vec<u8>
function reqBody(): ArrayBuffer
public func ReqBodyRaw() -> String
Body Field​
Returns the value for the provided key, if the request body is formatted as JSON:
- Rust
- AssemblyScript 🧪
- Swift 🧪
pub fn body_field(key: &str) -> String
function reqBodyField(key: string): string
public func ReqBodyField(key: String) -> String
Header​
Returns the header value for the provided key:
- Rust
- AssemblyScript 🧪
- Swift 🧪
pub fn header(key: &str) -> String
function reqHeader(key: string): string
public func ReqHeader(key: String) -> String
URL Parameter​
Returns the URL parameter for the provided key,
Example: /api/v1/user/:uuid
- Rust
- AssemblyScript 🧪
- Swift 🧪
pub fn url_param(key: &str) -> String
function reqURLParam(key: string): string
public func ReqParam(key: String) -> String
State​
Returns the value from request state for the provided key:
- Rust
- AssemblyScript 🧪
- Swift 🧪
pub fn state(key: &str) -> Option<String>
function reqState(key: string): string
public func State(key: String) -> String