VillageSQL is a drop-in replacement for MySQL with extensions.
All examples in this guide 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:
| Field | Description |
|---|---|
status | HTTP status code as a string ("200", "404", etc.) |
content_type | Value of the Content-Type response header |
headers | Array of [name, value] pairs for all response headers |
content | Response body |
The charset conversion
VEF STRING functions return binary charset. Before passing the result toJSON_VALUE or JSON_EXTRACT, wrap it with CONVERT(... USING utf8mb4):
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
| Function | Description |
|---|---|
http_get(url) | GET request |
http_post(url, content_type, body) | POST with body |
http_put(url, content_type, body) | PUT with body |
http_delete(url) | DELETE request |
http_patch(url, content_type, body) | PATCH with body |
http_request(method, url, headers_json, body, content_type, options_json) | Any method, custom headers, options |
url_encode(text) | Percent-encode a string |
url_decode(text) | Decode a percent-encoded string |
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.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 to avoid hitting the default query timeout.
Troubleshooting
| Problem | Solution |
|---|---|
FUNCTION http_get does not exist | Run INSTALL EXTENSION vsql_http |
| Returns NULL | Connection failed or NULL input — verify the URL and check network access from the server host |
JSON_VALUE returns NULL | Response body too large — use JSON_UNQUOTE(JSON_EXTRACT(...)) |
| Garbled JSON parsing | Forgot CONVERT(... USING utf8mb4) — wrap the function call |
| Query times out | Set SET SESSION max_execution_time = 30000 before the query |
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

