Otter
Snippets
Otter
Upstream Otter 1.0.1 Tested
HTTP GET Request with Client Lifecycle
Issue an asynchronous HTTP GET request and await completion response.
Architecture & Runtime Preview
Otter 1.0.1Zero-dependency Otter 1.0.1 snippet (Web & Network). Copy the parameterized template or run the self-contained example.
- 1Category: Web & Network
- 2Attribution: Otter Core Language Spec (D116B)
- 3Zero external pack dependencies — paste directly into any .ot file
Source Code (2 files)
start get from ${url} and call it ${req}
tries is 0
while ${req} is pending and tries is less than 50
wait 20 milliseconds
tries is tries plus 1
.
if ${req} is completed
say "Response:" response of ${req}
.
listen for tcp on port 0 and call it srv
port is local port of srv
baseParts are
"http://127.0.0.1:"
port
.
join baseParts with "" into baseUrl
on connection to srv
c is incoming connection
on data from c
send bytes from text "HTTP/1.1 200 OK\nContent-Type: text/plain\nContent-Length: 12\nConnection: close\n\nHello Otter!" through c
close tcp c
.
.
url is baseUrl plus "/api/ping"
start get from url and call it req
tries is 0
while req is pending and tries is less than 50
wait 30 milliseconds
tries is tries plus 1
.
if req is not completed
fail with "http request did not complete"
.
say "HTTP Response:" response of req
if not response of req contains "Hello Otter!"
fail with "http response body mismatch: expected Hello Otter!"
.
stop tcp srv
Installation & Usage
otter snippet inspect http-get-request
Copy template.ot directly into your .ot source file, or run example.ot with 'otter run example.ot'.