HTTP
Call your own backends or third-party APIs from presentation code.
Public surface (http): get · post · put · patch · delete · request
Behavior by environment
Section titled “Behavior by environment”| Environment | Transport |
|---|---|
Native app (isApp()) |
Proxied through the host (POST …/http/request) — no browser CORS |
| CDN / browser | Standard fetch — CORS rules apply |
Signatures
Section titled “Signatures”get(url: string, options?: HTTPOptions): Promise<HTTPResponse>post(url: string, body?: unknown, options?: HTTPOptions): Promise<HTTPResponse>put(url: string, body?: unknown, options?: HTTPOptions): Promise<HTTPResponse>patch(url: string, body?: unknown, options?: HTTPOptions): Promise<HTTPResponse>delete(url: string, options?: HTTPOptions): Promise<HTTPResponse>request(url: string, options?: HTTPRequestOptions): Promise<HTTPResponse>
interface HTTPOptions { headers?: Record<string, string> timeout?: number // default 30_000 responseType?: 'json' | 'text' | 'blob' // default 'json'}
interface HTTPRequestOptions extends HTTPOptions { method?: 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE' body?: unknown}
interface HTTPResponse { status: number statusText: string headers: Record<string, string> data: unknown}Examples
Section titled “Examples”import mobilelocker from '@mobilelocker/javascript-sdk'
// GETconst response = await mobilelocker.http.get('https://api.example.com/data')// response.status, response.statusText, response.headers, response.data
// POST — body is the second argument; options are the thirdconst created = await mobilelocker.http.post( 'https://api.example.com/submit', { leadId: 42 }, { headers: { 'X-Client': 'mobilelocker-presentation' }, timeout: 15_000, },)
// Full controlconst res = await mobilelocker.http.request('https://api.example.com/item/1', { method: 'PUT', body: { name: 'Updated' }, responseType: 'json',})Errors
Section titled “Errors”| Situation | Thrown |
|---|---|
| Network failure / timeout / offline (browser path) | MobileLockerHTTPError (request_timeout, not_connected, …) |
| Non-2xx HTTP status (browser path) | MobileLockerHttpResponseError — inspect status, statusText, headers, data |
See Errors.
- Prefer HTTPS endpoints your team owns
- Do not embed long-lived secrets in presentation JS
- For Mobile Locker platform data, use domain APIs (
crm,user,data, …) instead of inventing host REST paths
API reference
Section titled “API reference”- Module:
http - Types:
HTTPResponse,HTTPOptions,HTTPRequestOptions