HTTP Requests
Devlish provides HTTP verbs as native keywords for interacting with web APIs. Each verb compiles to a dedicated opcode and dispatches through the host runtime.
GET Requests
Section titled “GET Requests”Retrieve data from a URL:
Get the url at "https://api.example.com/projects" as responseprojects equals body of responsePOST Requests
Section titled “POST Requests”Submit data to an endpoint:
payload equals record with "Solar Farm" as name and 5000000 as valuePost to "https://api.example.com/projects" with payload as responsePUT Requests
Section titled “PUT Requests”Update an existing resource:
updated_item equals record with "complete" as statusPut 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.