Requester Library Reference
The requester
library (also known as the HTTP fetcher) brings full HTTP client capabilities into EasyBite. With just a few calls you can:
- Connect to a base URL and keep a shared HTTP client
- Perform GET, POST, PUT, DELETE, PATCH, HEAD, OPTIONS requests
- Customize timeouts, headers, query parameters, request bodies
- Manage cookies in a simple in‑memory jar
- Parse JSON or retrieve plain text responses
Importing
import requester
// or select specific functions
from requester import connect, get, post, request, getjson
Available Functions
Function | Parameters | Description |
---|---|---|
connect(base_url) | base_url (String) | Create and store a shared HTTP client, set the default base URL. |
settimeout([client,] s) | client (HTTPClient, optional), s (Number seconds) | Update the request timeout. If no client passed, updates the last one. |
request([client,] method, [url], [body], [options]) | method (String), url (String, optional), body (String, optional), options (Dictionary, optional) | Make a generic HTTP request. Options can include "headers" or "params" dictionaries. |
get([client,] [url], [options]) | like request with method="GET" | Convenience for GET requests. |
post([client,] [url], body, [options]) | like request with method="POST" | Convenience for POST. |
put([client,] [url], body, [options]) | like above | Convenience for PUT. |
delete([client,] [url], [options]) | like above | Convenience for DELETE. |
head([client,] [url], [options]) | like above | Convenience for HEAD. |
patch([client,] [url], body, [options]) | like above | Convenience for PATCH. |
options([client,] [url], [options]) | like above | Convenience for OPTIONS. |
getresponse([client,] [url_or_response]) | client (optional), url_or_response (String or existing response Dict) | Return a full response dictionary with keys "status" , "headers" , "body" . |
getjson([client,] [url_or_response], [options]) | as getresponse , but parses "body" as JSON and returns a Value tree. | Fetch and parse JSON in one call. |
gettext([client,] [url_or_response], [options]) | as getresponse but returns the "body" string. | Fetch plain text. |
setcookie(name, value) | name , value (Strings) | Store a cookie in the global jar. |
getcookies() | — | Return a dictionary of all stored cookies. |
clearcookies() | — | Remove all cookies from the jar. |
close([client]) | client (optional) | Drop the given or last HTTP client. |
Detailed Explanation
-
Connecting
Userequester.connect("https://api.example.com")
to create a long‑lived HTTP client and set a default base URL. Subsequent calls toget
,post
, or the genericrequest
will resolve relative paths against this base—no need to repeat the domain. -
Timeouts
By default, the client uses a standard timeout. Callrequester.settimeout(10)
(seconds) orrequester.settimeout(client, 30)
to adjust it globally or per‑client. -
Making Requests
-
Generic:
set resp to requester.request("POST", "/users", "{\"name\":\"Alice\"}", {"headers": {"Content-Type":"application/json"}})
The generic
request
takes:- method (e.g.
"GET"
,"PUT"
) - URL (absolute or relative)
- optional body string
- optional options dict with
"headers"
and/or"params"
(for query string on GET)
- method (e.g.
-
Convenience:
set r1 to requester.get("/items", {"params": {"page":"2"}})
set r2 to requester.post("/login", "{\"user\":\"bob\"}", {"headers": {"Accept":"application/json"}})
-
-
Inspecting Responses
All requests return a dictionary with:"status"
→ HTTP status code (Number)"headers"
→ a dictionary of header‑name → header‑value (String)"body"
→ response body (String)
Example:
set resp to requester.getresponse("https://httpbin.org/get")
show(resp["status"]) // e.g. 200
show(resp["headers"]["Content-Type"])
show(resp["body"]) // raw JSON text -
Parsing JSON
To immediately parse JSON into EasyBite values:set data to requester.getjson("https://api.example.com/data")
// `data` is now a nested structure of dictionaries, arrays, numbers, and strings
show(data["items"][0]["name"]) -
Cookies
Manage cookies automatically with:set _ to requester.setcookie("session", "abc123")
set all to requester.getcookies()
show(all)
set _ to requester.clearcookies() -
Closing
When you’re done, drop the client to free resources:set _ to requester.close()
Examples
import requester
// 1. Connect and GET
set client to requester.connect("https://httpbin.org")
set resp to requester.get(client, "/get", {"params": {"foo":"bar"}})
show(resp["status"]) // 200
show(resp["body"]) // JSON text
// 2. Parse JSON
set json to requester.getjson(client, "/get")
show(json["args"]["foo"]) // "bar"
// 3. POST with headers
set resp2 to requester.post(client, "/post", "{\"x\":1}", {"headers":{"Content-Type":"application/json"}})
show(resp2["status"])
show(resp2["body"])
// 4. Timeout example
set _ to requester.settimeout(client, 5)
// will error if server takes >5s
// 5. Cookies
set _ to requester.setcookie("token","xyz")
set ck to requester.getcookies()
show(ck["token"]) // "xyz"
set _ to requester.clearcookies()
// 6. Close when done
set _ to requester.close(client)
Conclusion
The requester
module makes HTTP in EasyBite:
- Simple to import (
import requester
), - Flexible (generic
request
plus convenience methods), - Powerful (timeout, headers, query params, cookies, JSON parsing).
Combine these calls with EasyBite’s control flow (repeat while … end repeat
) to build scripts, API clients, or even small web‑crawlers entirely in EasyBite.