Skip to content

HTTP

Call your own backends or third-party APIs from presentation code.

Public surface (http): get · post · put · patch · delete · request

Environment Transport
Native app (isApp()) Proxied through the host (POST …/http/request) — no browser CORS
CDN / browser Standard fetchCORS rules apply
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
}
import mobilelocker from '@mobilelocker/javascript-sdk'
// GET
const 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 third
const created = await mobilelocker.http.post(
'https://api.example.com/submit',
{ leadId: 42 },
{
headers: { 'X-Client': 'mobilelocker-presentation' },
timeout: 15_000,
},
)
// Full control
const res = await mobilelocker.http.request('https://api.example.com/item/1', {
method: 'PUT',
body: { name: 'Updated' },
responseType: 'json',
})
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