BINDING
upstream is the inspected response result for a JSON response, proxy, byte response, or following server statement.
SERVER / HTTP
Make a controlled outbound request
http is a server-only declaration for outbound Rust runtime requests. It gives the response a named binding while keeping URLs, credentials, and response handling inside the server boundary.
Server documentation
MENTAL MODEL
Declare the response binding first
The name after http is the response variable for later statements. Use one lowercase method value and keep base, path, headers, timeout, and response mode explicit.
handler fetchStatus async req
http upstream method:"get" base:env.MEDIA_BASE_URL path:"/api/status" mode:"bytes" headers:[{ name:"Accept" value:"application/json" }]
return response json:{ ok:upstream.ok status:upstream.status }BINDING
upstream is the inspected response result for a JSON response, proxy, byte response, or following server statement.
METHOD
method accepts get, post, put, patch, or delete. The lowercase value becomes the direct Rust HTTP request method.
BOUNDARY
http is server-only. Views and client targets do not receive outbound network authority or server environment values.
PROXY AND SAFETY
Keep authority explicit
Declare base and bearer names in .env.example, supply values through .env or the process environment, and reference them only from server source. Headers are validated, Authorization belongs in bearer, and redirect plus timeout policy remain visible in source.
handler chatCompletions async req
const body value:req.json
http upstream method:"post" base:env.OPENROUTER_BASE_URL path:"/api/v1/chat/completions" bearer:env.OPENROUTER_API_KEY json:body mode:"proxy" timeoutMs:10000
return response proxy:upstreamResponse modes
json is the default for inspectable status and data. bytes preserves an upstream byte binding, and proxy forwards a controlled upstream response.
Migration
Replace let upstream = http.get, http.post, or http.request with http upstream method:"...". Legacy expression forms are rejected.