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.
GET Requests
Section titled “GET Requests”Retrieve data from a URL:
Get the url at "https://api.example.com/projects" as responsePOST Requests
Section titled “POST Requests”Submit data to an endpoint:
Post to "https://api.example.com/projects" with payload as responsePUT Requests
Section titled “PUT Requests”Update an existing resource:
Put to "https://api.example.com/projects/42" with updated_item as responseDELETE Requests
Section titled “DELETE Requests”Remove a resource:
Delete the url at "https://api.example.com/projects/42" as responseResponse Structure
Section titled “Response Structure”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 dataOtherwise: Print "Request failed"Syntax Reference
Section titled “Syntax Reference”| 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 |
Error Handling
Section titled “Error Handling”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 responseOtherwise: Print last_error data equals record with "unavailable" as statusBuilding Request Bodies
Section titled “Building Request Bodies”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_scorePermissions
Section titled “Permissions”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.