HTTP requests
get, post, put and delete talk to web services. They work the same in console programs and in web applications.
Fetching
Otter
get "https://api.example.com/data" into result
get "https://api.example.com/data" as json into data
as json parses the body into ordinary Otter objects and lists that you read with of.
Sending
Otter
post "hello" to "https://api.example.com/echo" into reply
put "updated" to "https://api.example.com/items/1" into reply
delete from "https://api.example.com/items/1" into reply
Options
An indented block adds headers, cookies, redirect handling and a timeout to one request:
Otter
get "https://api.example.com/data" into result
with header "Authorization" is "Bearer token"
with cookies
following redirects
with timeout 10 seconds
A request that cannot complete, or that times out, is a readable Otter error you can handle with try and otherwise.
Next: web servers