VillageSQL is a drop-in replacement for MySQL with extensions.
All examples on this page work on VillageSQL. Install Now →
vsql_http extension adds http_get(), http_post(), and the full range of HTTP methods directly to SQL — so you can call external APIs from the same place the data lives.
The Problem: Leaving the Database for Every API Call
A typical pattern without VillageSQL:With VillageSQL: HTTP from SQL
http_get(url) makes a GET request and returns a JSON string with the full response.
vsql_http returns the same JSON shape:
The charset conversion
On VillageSQL 0.0.6 and earlier, VEF STRING functions return binary charset. Before passing the result toJSON_VALUE or JSON_EXTRACT, wrap it with CONVERT(... USING utf8mb4):
CONVERT is no longer required there — but it is harmless to keep, and every example below still uses it for compatibility with 0.0.6 and earlier. Assign to a variable with CONVERT once and reuse the variable to avoid repeating the cast.
POST Requests
http_post(url, content_type, body) sends a POST with a body:
Custom Headers and Other Methods
http_request(method, url, headers_json, body, content_type, options_json) handles any method with custom headers:
headers_json argument is a JSON object where keys are header names and values are header values.
All available functions
All functions return NULL for NULL input. On connection failure (refused
connection, DNS failure, timeout), the HTTP functions also return NULL and
raise a warning carrying curl’s error message — check it with
SHOW WARNINGS
when a request seems to disappear.
URL Encoding
url_encode() and url_decode() handle percent-encoding for query parameters:
Known Limitations
256KB response cap — Responses larger than 256KB are truncated. This covers typical API payloads used in SQL queries; it’s not suited for large file downloads. A response cut off by this cap is no longer valid JSON:JSON_EXTRACT/JSON_UNQUOTE raise ERROR 3141 on it, while JSON_VALUE returns NULL with a Warning 3141 instead of erroring, under its default NULL ON ERROR behavior.
JSON_VALUE size limit — JSON_VALUE returns NULL when the extracted value exceeds MySQL’s internal size limit. For large response bodies, use JSON_UNQUOTE(JSON_EXTRACT(...)) instead:
max_execution_time does not bound or interrupt a blocking vsql_http call — a slow or unreachable endpoint holds the statement for its own connect/read timeout regardless. http_get/http_post/http_put/http_delete/http_patch take no options; only http_request(method, url, headers_json, body, content_type, options_json) accepts a timeout, as {"timeout": N} in seconds in its options_json argument (default 30). Use http_request instead of the shorthand functions when you need to shorten it (see HTTP Webhooks).
Troubleshooting
Next Steps
- Enriching rows with API data — pull live external data into query results
- Sending webhooks from triggers — push row changes to external services automatically
See also
- Enriching Rows with External API Data — a practical pattern for HTTP-based data enrichment
- Sending Webhooks from Triggers — event-driven HTTP calls from triggers
- JSON in MySQL — parsing the JSON responses that HTTP requests return
- Serving Tables as a REST API — the same server answering HTTP instead of making requests