XDPXI's Documentation
HTTP

Client Functions

Required version: Sponge >=1.0.5

Make HTTP requests to external servers. The HTTP client functions allow you to send requests and receive responses from remote servers.

http.send(url, method, body?)

Sends an HTTP request to the specified URL with the given method and optional body.

Parameters:

  • url (string) - The URL to request (e.g., "http://example.com/api")
  • method (string) - HTTP method: "GET", "POST", "PUT", "DELETE", etc.
  • body (string, optional) - Request body for POST/PUT requests

Returns: string - Full HTTP response (headers and body)

Example:

let response = http.send("http://example.com/api", "GET");
print(response);

POST Request:

let data = "name=Alice&age=30";
let response = http.send("http://example.com/api", "POST", data);
print(response);

JSON POST:

let json_data = http.json({ name: "Alice", age: 30 });
let response = http.send("http://example.com/api", "POST", json_data);
print(response);

http.get(url)

Sends a GET request to the specified URL.

Parameters:

  • url (string) - The URL to request

Returns: string - Full HTTP response (headers and body)

Example:

let response = http.get("http://example.com/api/users");
print(response);

Fetching JSON API:

let response = http.get("http://api.example.com/data");
# Response contains full HTTP response, parse as needed
print(response);

http.post(url, body)

Sends a POST request to the specified URL with a request body.

Parameters:

  • url (string) - The URL to request
  • body (string) - The request body

Returns: string - Full HTTP response (headers and body)

Example:

let body = "key=value&foo=bar";
let response = http.post("http://example.com/api", body);
print(response);

Posting JSON:

let data = { name: "Alice", email: "alice@example.com" };
let json = http.json(data);
let response = http.post("http://example.com/api/users", json);
print(response);