HTTP & Network

OcaltQL provides full network access — HTTP requests via FETCH and CURL, IP aliasing and proxy routing, user agent control, real-time communication via WebSocket, and low-level TCP and UDP connections.

FETCH

See Fetch & Curl for the full FETCH reference. The essentials are covered here alongside the extended network capabilities.

Basic FETCH
FETCH 'https://api.example.com/data' SET ?response
AFTER FETCH 'https://api.example.com/data' METHOD 'post' BODY 'name=Alice&age=30' SET ?response
AFTER FETCH 'https://api.example.com/data' METHOD 'post' BODY '{"name":"Alice"}' HEADER 'Content-Type: application/json' SET ?response
AFTER FETCH 'https://api.example.com/data' HEADER 'Auth: token' HEADER 'X-Custom: value' SET ?response
AFTER FETCH 'https://api.example.com/data' TIMEOUT 10 SECONDS SET ?response
AFTER FETCH 'https://example.com/image.jpg' INTO '/root/image.jpg'
AFTER FETCH 'https://api.example.com/data' SET ?code WITH STATUS AND SET ?body WITH DATA
AFTER EMIT ?code
AFTER EMIT ?body

IP Aliasing & Proxy

IP routes the request from a specific source IP. IP ALIAS hides the real IP behind an alias. PROXY routes through an HTTP or SOCKS5 proxy. All are modifiers on FETCH and can be combined with any other modifier.

IP Routing
FETCH 'https://api.example.com/data' IP '192.168.1.100' SET ?response
AFTER FETCH 'https://api.example.com/data' IP ALIAS '10.0.0.5' SET ?response
Proxy
FETCH 'https://api.example.com/data' PROXY 'http://proxy.example.com:8080' SET ?response
AFTER FETCH 'https://api.example.com/data' PROXY 'socks5://127.0.0.1:1080' SET ?response

User Agent Control

USER AGENT sets the user agent string sent with the request. Any string is valid. Pass an empty string to send no user agent.

User Agent
FETCH 'https://api.example.com/data' USER AGENT 'Mozilla/5.0 (Windows NT 10.0; Win64; x64)' SET ?response
AFTER FETCH 'https://api.example.com/data' USER AGENT 'Mozilla/5.0 (iPhone; CPU iPhone OS 16_0 like Mac OS X)' SET ?response
AFTER FETCH 'https://api.example.com/data' USER AGENT 'OcaltQL-Bot/1.0' SET ?response
AFTER FETCH 'https://api.example.com/data' USER AGENT '' SET ?response

Combined Modifiers

All modifiers — IP, proxy, user agent, headers, method, body, timeout — can be combined in any order on a single FETCH.

Full Modifier Combination
FETCH 'https://api.example.com/data' IP '203.0.113.1' USER AGENT 'CustomBot/1.0' HEADER 'X-Real-IP: 203.0.113.1' HEADER 'Referer: https://example.com' SET ?response

CURL

CURL is a direct alias for FETCH. Every modifier available on FETCH works identically on CURL.

CURL
CURL 'https://api.example.com/data' SET ?response

STATUS

STATUS sets the HTTP response status code for the current script execution. It has no effect on execution flow — the script continues normally after it runs.

Setting a Status Code
STATUS 404
AFTER EMIT "Not found"
Conditional Status Codes
IF ?user IS NULL
OPEN
  STATUS 401
  AFTER EMIT "Unauthorized"
CLOSE
OR
OPEN
  STATUS 200
  AFTER EMIT "Welcome, " & ?user("email")
CLOSE
STATUS does not stop execution. Unlike REDIRECT, setting a status code does not end the script — statements after it still run normally. Set it as early or as late as needed; only the final value set before the script ends is sent.

WebSocket

WEBSOCKET opens a WebSocket connection. SEND transmits a message. RECEIVE blocks until a message arrives and captures it. CLOSE terminates the connection.

WebSocket Connection
(* Open connection *)
WEBSOCKET 'wss://socket.example.com' SET ?ws

(* Send message *)
AFTER SEND ?ws 'hello'

(* Receive message *)
AFTER RECEIVE ?ws SET ?msg
AFTER EMIT ?msg

(* Close connection *)
AFTER CLOSE ?ws

TCP

TCP opens a raw TCP connection to a host and port. SEND transmits data. RECEIVE reads incoming data.

TCP Connection
(* Connect *)
TCP '192.168.1.1' PORT 8080 SET ?tcp

(* Send *)
AFTER SEND ?tcp 'hello'

(* Receive *)
AFTER RECEIVE ?tcp SET ?data
AFTER EMIT ?data

UDP

UDP sends a datagram to a host and port. UDP is connectionless — there is no persistent connection object and no RECEIVE on the same call.

UDP Send
UDP '192.168.1.1' PORT 53 SEND 'query'
SEND and RECEIVE are shared verbs across WebSocket and TCP. The connection variable (?ws, ?tcp) determines the protocol. CLOSE terminates any open connection by its variable.