HTTP client
You can use the http
namespace of the Runnable API to make HTTP requests from your Runnable code. These methods are currently the only way to access the network from Runnable code.
Arbitrary socket and network access is not currently possible.
- Rust
- JavaScript/TypeScript
- AssemblyScript
In Rust these methods are available under the http
module:
# Use the "http" module
use suborbital::http;
# Invoke the "Get" method
http::get(…)
In JavaScript and TypeScript the methods live on the http
import:
import { http } from "@suborbital/runnable"
All HTTP requests return a HttpResponse
object supporting various payload formats:
export class HttpResponse {
arrayBuffer(): ArrayBuffer {}
json(): object {}
text(): string {}
}
The headers
parameter may be specified as string header name/value pairs:
type Headers = { [key: string]: string };
In AssemblyScript all methods are prefixed with http
:
// Import then invoke "Get" method
import { httpGet } from '@suborbital/suborbital'
httpGet(…)
The following namespace methods are available:
GET
Performs an HTTP GET request:
- Rust
- JavaScript & TypeScript
- AssemblyScript
pub fn get(url: &str, headers: Option<BTreeMap<&str, &str>>) -> Result<Vec<u8>, RunErr>
http.get(url: string, headers?: Headers): HttpResponse
function httpGet(url: string, headers: Map<string, string> | null): Result
HEAD
Performs an HTTP HEAD request:
- Rust
- JavaScript & TypeScript
- AssemblyScript
pub fn get(url: &str, headers: Option<BTreeMap<&str, &str>>) -> Result<Vec<u8>, HostErr>
http.head(url: string, headers?: Headers): HttpResponse
function httpHead(url: string, headers: Map<string, string> | null): Result
OPTIONS
Performs an HTTP OPTIONS request:
- Rust
- JavaScript & TypeScript
- AssemblyScript
pub fn options(url: &str, headers: Option<BTreeMap<&str, &str>>) -> Result<Vec<u8>, HostErr>
http.options(url: string, headers?: Headers): HttpResponse
function httpOptions(url: string, headers: Map<string, string> | null): Result
POST
Performs an HTTP POST request:
- Rust
- JavaScript & TypeScript
- AssemblyScript
pub fn post(url: &str, body: Option<Vec<u8>>, headers: Option<BTreeMap<&str, &str>>) -> Result<Vec<u8>, RunErr>
http.post(url: string, body: string | Uint8Array, headers?: Headers): HttpResponse
function httpPost(url: string, body: ArrayBuffer, headers: Map<string, string> | null): ArrayBuffer
PUT
Performs an HTTP PUT request:
- Rust
- JavaScript & TypeScript
- AssemblyScript
- Swift
pub fn put(url: &str, body: Option<Vec<u8>>, headers: Option<BTreeMap<&str, &str>>) -> Result<Vec<u8>, HostErr>
http.put(url: string, body: string | Uint8Array, headers?: Headers): HttpResponse
function httpPut(url: string, body: ArrayBuffer, headers: Map<string, string> | null): Result
public func HttpPut(url: String, body: String) -> String
PATCH
Performs an HTTP PATCH request:
- Rust
- JavaScript & TypeScript
- AssemblyScript
- Swift
pub fn patch(url: &str, body: Option<Vec<u8>>, headers: Option<BTreeMap<&str, &str>>) -> Result<Vec<u8>, RunErr>
http.patch(url: string, body: string | Uint8Array, headers?: Headers): HttpResponse
function httpPatch(url: string, body: ArrayBuffer, headers: Map<string, string> | null): ArrayBuffer
public func HttpPatch(url: String, body: String) -> String
DELETE
Performs an HTTP DELETE request:
- Rust
- JavaScript & TypeScript
- AssemblyScript
- Swift
pub fn delete(url: &str, headers: Option<BTreeMap<&str, &str>>) -> Result<Vec<u8>, RunErr>
http.delete(url: string, headers?: Headers): HttpResponse
function httpDelete(url: string, headers: Map<string, string> | null): ArrayBuffer
public func HttpDelete(url: String) -> String