Skip to main content
Sends an HTTP request to an external URL and returns the response as a string.

Signature

sqlpage.fetch(url_or_request TEXT|JSON) -> TEXT

Parameters

url_or_request
TEXT or JSON
required
Either a URL string for simple GET requests, or a JSON object with request details

Return Value

return
TEXT
The response body as text, or NULL if input is NULL

Description

The fetch() function makes HTTP requests to external APIs and returns the response body. It supports GET, POST, PUT, DELETE, and other HTTP methods.

Examples

Simple GET Request

SET url = 'https://api.example.com/users';
SET response = sqlpage.fetch($url);

SELECT 'code' as component;
SELECT $response as contents, 'json' as language;

POST Request with JSON

SET request = json_object(
    'method', 'POST',
    'url', 'https://api.example.com/users',
    'headers', json_object(
        'Content-Type', 'application/json'
    ),
    'body', json_object(
        'name', 'John Doe',
        'email', 'john@example.com'
    )
);

SET response = sqlpage.fetch($request);

Authenticated Request

SET request = json_object(
    'url', 'https://api.example.com/data',
    'username', 'my_username',
    'password', 'my_password'
);

SET response = sqlpage.fetch($request);

Build docs developers (and LLMs) love