Skip to content

HTTP Requests

An HTTP request exchanges data with a web service. A program can fetch information, submit a record, update a resource, or request its deletion. Devlish provides a separate statement for each of these actions and stores the service’s response in a named variable.

This page explains the request forms and how to inspect a response. Examples use placeholder API addresses and assume the request body variables already exist. Network access depends on the host runtime and declared permissions.

Retrieve data from a URL:

Get the url at "https://api.example.com/projects" as response

Submit data to an endpoint:

Post to "https://api.example.com/projects" with payload as response

Update an existing resource:

Put to "https://api.example.com/projects/42" with updated_item as response

Remove a resource:

Delete the url at "https://api.example.com/projects/42" as response

Every HTTP request returns a record with three fields:

Field Type Description
status number HTTP status code (200, 404, etc.)
headers record Response headers
body record or string Parsed JSON if content-type is JSON, otherwise raw text
Get the url at "https://api.example.com/data" as response
If status of response equals 200:
data equals body of response
Print data
Otherwise:
Print "Request failed"
Verb Syntax Has Body
Get Get the url at "<url>" as <var> No
Post Post to "<url>" with <body> as <var> Yes
Put Put to "<url>" with <body> as <var> Yes
Delete Delete the url at "<url>" as <var> No

HTTP requests can fail due to network errors or host restrictions. Use Try/Otherwise for recovery:

Try:
Get the url at "https://api.example.com/status" as response
If status of response >= 400:
Fail with "API returned error"
data equals body of response
Otherwise:
Print last_error
data equals record with "unavailable" as status

Construct records with the fields your API expects:

request_body equals record with "enterprise" as tier and 500000 as deal_size and true as active
Post to "https://api.example.com/assess" with request_body as response
If status of response equals 200:
risk_score equals score of body of response
Print risk_score

Programs that make HTTP requests should declare the permission in their manifest:

Permissions:
HTTP requests to "api.example.com"

Without a manifest, HTTP requests are unrestricted. With a manifest, undeclared domains are blocked at runtime.