Module: web
http
Back to Index http(url: string, options: HttpRequestOptions): HttpResponse
http
function allows a Reactor to make external HTTP requests.
Availability
Discount | Rule | Reactor |
---|---|---|
Security
All external requests must be done using HTTPS. It’s possible to restrict which hostnames are allowed on a system
level by setting the
reactors/effects/httpRequest/allowedHosts
Examples
GET request
import { http } from 'web'
export method(:nothing) => http( 'https://example.com' { headers = { 'Authorization' -> 'Bearer <token>' } })
POST request
If Content-Type
is set to application/json
, any non-text value will be converted into JSON automatically.
import { http } from 'web'
export method(:nothing) => http( 'https://example.com' { method = 'POST' headers = { 'Authorization' -> 'Bearer <token>' 'Content-Type' -> 'application/json' } body = { prop1 = 'value' } })