Skip to main content
vsql_http makes HTTP requests from inside a query. A trigger can call a webhook, a SELECT can enrich rows from an API, and a scheduled event can push a summary somewhere, with no application layer in between. It is built on libcurl and returns every response as JSON.

Install

vsql_http.veb is already in the server’s lib/veb/ directory if you installed VillageSQL with the install script, the Docker image, or a release tarball. Install it into the server with one statement:
Confirm it is there:
To build it yourself, follow the build instructions in the repository.

What it adds

Every request function returns one JSON object with four fields: status, content_type, headers, and content.

Example

Fetch a URL and read two fields out of the response:
Build a query string safely:
On VillageSQL 0.0.6 and earlier the response carries the binary character set. A JSON function or a JSON column rejects it, so the example above without its CONVERT fails there with ERROR 3144 (22032): Cannot create a JSON value from a string with CHARACTER SET 'binary'. Inside JSON_OBJECT() or JSON_ARRAY() it is accepted but base64-encoded instead. Keep the CONVERT(... USING utf8mb4) on those versions; it is unnecessary on 0.0.7 and later, and harmless there.
A request blocks the statement that made it, for up to 30 seconds by default. Only http_request can shorten that, through its options argument, as in '{"timeout": 5}'. One call per row turns a table scan into a series of network round trips, so keep these calls off large result sets.

See also