### Installation Source: https://github.com/asg017/sqlite-http/blob/main/npm/sqlite-http/README.md Install the sqlite-http NPM package for Node.js. ```APIDOC ## Installation Install the `sqlite-http` package using npm: ```bash npm install sqlite-http ``` ``` -------------------------------- ### Example: Rate Limiting Requests Source: https://github.com/asg017/sqlite-http/blob/main/docs.md Demonstrates how to apply a rate limit to a series of HTTP GET requests. The `http_rate_limit` function is called first to set the delay between requests. ```sql SELECT http_rate_limit(250); SELECT http_get_body( printf('http://localhost:8000/%d', value) FROM generate_series(1, 1000) ); ``` -------------------------------- ### Install sqlite-http NPM Package Source: https://github.com/asg017/sqlite-http/blob/main/npm/sqlite-http/README.md Installs the sqlite-http package using npm. This command should be run on a supported platform. ```bash npm install sqlite-http ``` -------------------------------- ### SQL: Example Usage of http_get Source: https://github.com/asg017/sqlite-http/blob/main/docs.md Demonstrates how to use the http_get table function to retrieve the request URL, response status, and the length of the response body from a given URL. This example queries Google's homepage. ```SQL select request_url, response_status, length(response_body) from http_get('https://google.com'); /* ┌────────────────────┬─────────────────┬───────────────────────┐ │ request_url │ response_status │ length(response_body) │ ├────────────────────┼─────────────────┼───────────────────────┤ │ https://google.com │ 200 OK │ 14043 │ └────────────────────┴─────────────────┴───────────────────────┘ */ ``` -------------------------------- ### Install datasette-sqlite-http Plugin Source: https://github.com/asg017/sqlite-http/blob/main/python/datasette_sqlite_http/README.md Installs the datasette-sqlite-http plugin using the datasette CLI. This makes the sqlite-http extension available within Datasette instances. ```bash datasette install datasette-sqlite-http ``` -------------------------------- ### Usage with better-sqlite3 Source: https://github.com/asg017/sqlite-http/blob/main/npm/sqlite-http/README.md Example of loading the sqlite-http extension with the better-sqlite3 client. ```APIDOC ## Usage with better-sqlite3 To use `sqlite-http` with `better-sqlite3`, load the extension using `db.loadExtension()` and `sqlite_http.getLoadablePath()`. ### Request Example ```js import Database from "better-sqlite3"; import * as sqlite_http from "sqlite-http"; const db = new Database(":memory:"); db.loadExtension(sqlite_http.getLoadablePath()); const version = db.prepare("select http_version() as version").pluck().get(); console.log(version); // Expected output: "v0.2.0" ``` ### Response #### Success Response (200) - **version** (string) - The version of the http_version function. #### Response Example ```json { "version": "v0.2.0" } ``` ``` -------------------------------- ### Usage with node-sqlite3 Source: https://github.com/asg017/sqlite-http/blob/main/npm/sqlite-http/README.md Example of loading the sqlite-http extension with the node-sqlite3 client. ```APIDOC ## Usage with node-sqlite3 To use `sqlite-http` with `node-sqlite3`, load the extension using `db.loadExtension()` and `sqlite_http.getLoadablePath()`. ### Request Example ```js import sqlite3 from "sqlite3"; import * as sqlite_http from "sqlite-http"; const db = new sqlite3.Database(":memory:"); db.loadExtension(sqlite_http.getLoadablePath()); db.get("select http_version() as version", (err, row) => { if (err) { console.error(err.message); return; } console.log(row); // Expected output: { version: "v0.2.0" } }); ``` ### Response #### Success Response (200) - **version** (string) - The version of the http_version function. #### Response Example ```json { "version": "v0.2.0" } ``` ``` -------------------------------- ### SQLite CLI Usage Example Source: https://context7.com/asg017/sqlite-http/llms.txt Shows how to load and use the sqlite-http extension directly from the SQLite command-line interface (CLI). ```APIDOC ## Language Bindings: SQLite CLI ### Description Demonstrates the steps to load and utilize the sqlite-http extension when working directly within the SQLite command-line interface. ### Method N/A (CLI usage example) ### Endpoint N/A ### Parameters None ### Request Example ```sql -- Load the extension (replace './http0' with the actual path to your compiled extension) .load ./http0 -- Verify that the extension is loaded by checking its version SELECT http_version(); -- Make an HTTP GET request to an example API SELECT http_get_body('https://api.example.com/data'); ``` ### Response #### Success Response (200) Results of the executed SQL queries, including HTTP responses or version information. #### Response Example (Output will be the content returned by the API or the version string, depending on the query.) ``` -------------------------------- ### Install sqlite-http with Ruby Source: https://github.com/asg017/sqlite-http/blob/main/README.md Installs the sqlite-http gem for Ruby. This is the standard method for Ruby package management. ```bash gem install sqlite-http ``` -------------------------------- ### Install sqlite-http Python Package Source: https://github.com/asg017/sqlite-http/blob/main/python/sqlite_http/README.md Installs the sqlite-http package using pip. This is the standard way to add the package to your Python environment. ```bash pip install sqlite-http ``` -------------------------------- ### Python Usage Example Source: https://context7.com/asg017/sqlite-http/llms.txt Demonstrates how to load and use the sqlite-http extension within a Python application using the `sqlite3` module. ```APIDOC ## Language Bindings: Python ### Description Provides examples of how to integrate the sqlite-http extension into Python applications. It shows how to load the extension with full network capabilities and in a restricted 'no-network' mode. ### Method N/A (Language binding example) ### Endpoint N/A ### Parameters None ### Request Example ```python import sqlite3 import sqlite_http # Standard connection with full HTTP capabilities conn = sqlite3.connect(':memory:') conn.enable_load_extension(True) sqlite_http.load(conn) # Example: Fetching data from an API result = conn.execute("SELECT http_get_body('https://api.github.com/')").fetchone() print(result[0]) # No-network mode (only utility functions, no HTTP requests) conn2 = sqlite3.connect(':memory:') conn2.enable_load_extension(True) sqlite_http.load_no_network(conn2) # This works: Utility function example headers = conn2.execute("SELECT http_headers('X-Foo', 'bar')").fetchone() print(headers) # This would error in no-network mode: # conn2.execute("SELECT http_get_body('https://example.com')") ``` ### Response #### Success Response (200) Execution of SQL queries via the extension. #### Response Example (Output depends on the executed SQL queries, e.g., JSON response from an API or header information.) ``` -------------------------------- ### Get Loadable Path for node-sqlite3 Source: https://github.com/asg017/sqlite-http/blob/main/npm/sqlite-http/README.md Obtains the file system path to the sqlite-http extension, suitable for use with node-sqlite3's loadExtension method. This function automatically determines the correct path based on the installed optional dependencies and host system architecture. ```javascript import sqlite3 from "sqlite3"; import * as sqlite_http from "sqlite-http"; const db = new sqlite3.Database(":memory:"); db.loadExtension(sqlite_http.getLoadablePath()); ``` -------------------------------- ### Get Loadable Path for better-sqlite3 Source: https://github.com/asg017/sqlite-http/blob/main/npm/sqlite-http/README.md Obtains the file system path to the sqlite-http extension, suitable for use with better-sqlite3's loadExtension method. This function automatically determines the correct path based on the installed optional dependencies and host system architecture. ```javascript import Database from "better-sqlite3"; import * as sqlite_http from "sqlite-http"; const db = new Database(":memory:"); db.loadExtension(sqlite_http.getLoadablePath()); ``` -------------------------------- ### Node.js Usage Example Source: https://context7.com/asg017/sqlite-http/llms.txt Demonstrates how to load and use the sqlite-http extension within a Node.js application using `better-sqlite3`. ```APIDOC ## Language Bindings: Node.js ### Description Provides examples for using the sqlite-http extension in Node.js environments with the `better-sqlite3` library. It covers loading the extension for full network access and for a secure 'no-network' mode. ### Method N/A (Language binding example) ### Endpoint N/A ### Parameters None ### Request Example ```javascript import Database from "better-sqlite3"; import { getLoadablePath, entrypoint, entrypointNoNetwork } from "sqlite-http"; const db = new Database(":memory:"); // Load with full HTTP capabilities // Assumes the compiled extension is available at the path returned by getLoadablePath() db.loadExtension(getLoadablePath()); // Example: Fetching data from an API const prepare = db.prepare("SELECT http_get_body(?)"); const result = prepare.get("https://api.github.com/"); console.log(result); // Alternative: Load with no-network mode for security // const dbNoNetwork = new Database(":memory:"); // dbNoNetwork.loadExtension(getLoadablePath(), entrypointNoNetwork); // Now, only utility functions are available, not network requests. ``` ### Response #### Success Response (200) Execution of SQL queries via the extension. #### Response Example (Output depends on the executed SQL queries, e.g., JSON response from an API.) ``` -------------------------------- ### Get Supported Platform Information Source: https://github.com/asg017/sqlite-http/blob/main/npm/sqlite-http/README.md Retrieves the current Node.js process's platform and architecture to determine compatibility with sqlite-http. This is useful for verifying if your environment is supported. ```bash $ node -e 'console.log([process.platform, process.arch])' [ 'darwin', 'x64' ] ``` -------------------------------- ### SQL: Fetch data using http_get Source: https://github.com/asg017/sqlite-http/blob/main/docs.md Illustrates a basic GET request using the http_get table function to fetch data from a specified URL. It selects all columns from the result table, providing comprehensive details about the HTTP GET request. ```SQL select * from http_get('http://httpbin.org/get'); ``` -------------------------------- ### Get sqlite-http Extension Path in Python Source: https://github.com/asg017/sqlite-http/blob/main/python/sqlite_http/README.md Retrieves the absolute file path to the locally installed sqlite-http extension using the `loadable_http()` function. This path can be used with `sqlite3.Connection.load_extension()`. ```python import sqlite_http extension_path = sqlite_http.loadable_http() print(extension_path) # Example output: '/.../venv/lib/python3.9/site-packages/sqlite_http/http0' ``` -------------------------------- ### Make HTTP GET Request with Headers Source: https://github.com/asg017/sqlite-http/blob/main/docs.md Fetches only the header information from a URL using an HTTP GET request. It takes the URL, optional headers, and optional cookies. This is useful when only metadata is needed. ```sql SELECT http_get_headers( 'http://localhost:8000/resource' ); ``` -------------------------------- ### Load sqlite-http Extension with Datasette Source: https://github.com/asg017/sqlite-http/blob/main/README.md Demonstrates how to load the sqlite-http extension when starting Datasette. This enables Datasette to make HTTP requests, with an option to limit network access for security. ```bash datasette data.db --load-extension ./http0-no-net ``` -------------------------------- ### Example: Using Custom Headers Source: https://github.com/asg017/sqlite-http/blob/main/docs.md Shows how to include custom headers in an HTTP request. The `http_headers` function is used to construct the headers, which are then passed to the request function. ```sql SELECT http_get_body( 'http://localhost:8000/api/data', http_headers( 'Authorization', 'Bearer YOUR_TOKEN', 'X-Custom-Header', 'value' ) ); ``` -------------------------------- ### Make GET HTTP Request in SQL Source: https://github.com/asg017/sqlite-http/blob/main/README.md Demonstrates how to perform a simple HTTP GET request to a given URL using the `http_get_body` function. This function returns the response body of the request. It's useful for fetching HTML content or API responses. ```sql .load ./http0 select http_get_body('https://text.npr.org/'); ``` -------------------------------- ### Load sqlite-http Extension in Python Source: https://github.com/asg017/sqlite-http/blob/main/python/sqlite_http/README.md Demonstrates how to use the sqlite_http Python package to load the http extension into a sqlite3 connection. It shows how to get the extension path and then load it, followed by a query to verify the version. ```python import sqlite_http import sqlite3 conn = sqlite3.connect(':memory:') # Enable extension loading (required before loading) conn.enable_load_extension(True) # Load the sqlite-http extension sqlite_http.load(conn) # Disable extension loading after use for security conn.enable_load_extension(False) # Example query to check the http_version result = conn.execute('select http_version()').fetchone() print(result) # Expected output: ('v0.1.0') ``` -------------------------------- ### Example: Setting Request Timeout Source: https://github.com/asg017/sqlite-http/blob/main/docs.md Illustrates how to set a custom timeout for HTTP requests. The `http_timeout_set` function configures the maximum wait time for a response. ```sql SELECT http_timeout_set(5 * 1000); -- This request will return an error if it takes longer than 5 seconds SELECT http_get_body('http://example.com/slow-resource'); ``` -------------------------------- ### Publish Datasette with datasette-sqlite-http Plugin Source: https://github.com/asg017/sqlite-http/blob/main/python/datasette_sqlite_http/README.md Publishes a Datasette instance to a cloud platform (e.g., Cloud Run) while installing the datasette-sqlite-http plugin. This ensures the HTTP SQL functions are available in the deployed service. ```bash datasette publish cloudrun data.db --service=my-service --install=datasette-sqlite-http ``` -------------------------------- ### Response Headers Functions Source: https://context7.com/asg017/sqlite-http/llms.txt Functions to retrieve only response headers for GET, POST, and custom method requests. ```APIDOC ## Response Headers Functions ### http_get_headers(url, [headers], [cookies]) Performs a GET request and returns only the response headers in wire format. #### Parameters * **url** (TEXT) - The URL to send the GET request to. * **headers** (TEXT, Optional) - HTTP headers in wire format, constructed using `http_headers()`. * **cookies** (TEXT, Optional) - Cookies in JSON format, constructed using `http_cookies()`. ### Request Example ```sql SELECT http_get_headers('https://api.github.com/'); /* Access-Control-Allow-Origin: * Cache-Control: public, max-age=60, s-maxage=60 Content-Security-Policy: default-src 'none' Content-Type: application/json; charset=utf-8 ... */ ``` ### http_post_headers(url, [headers], [body], [cookies]) Performs a POST request and returns only the response headers. #### Parameters * **url** (TEXT) - The URL to send the POST request to. * **headers** (TEXT, Optional) - HTTP headers in wire format, constructed using `http_headers()`. * **body** (TEXT, Optional) - The request body. * **cookies** (TEXT, Optional) - Cookies in JSON format, constructed using `http_cookies()`. ### Request Example ```sql SELECT http_post_headers( 'https://httpbin.org/post', http_headers('Content-Type', 'application/json'), '{"test": true}' ); ``` ### http_do_headers(method, url, [headers], [body], [cookies]) Performs a request with a custom method and returns only the response headers. #### Parameters * **method** (TEXT) - The HTTP method (e.g., 'OPTIONS'). * **url** (TEXT) - The URL to send the request to. * **headers** (TEXT, Optional) - HTTP headers in wire format, constructed using `http_headers()`. * **body** (TEXT, Optional) - The request body. * **cookies** (TEXT, Optional) - Cookies in JSON format, constructed using `http_cookies()`. ### Request Example ```sql SELECT http_do_headers('OPTIONS', 'https://api.example.com/resource'); ``` ### Response #### Success Response (200) * **headers** (TEXT) - The response headers in wire format. ``` -------------------------------- ### Get Full HTTP Request/Response Metadata in SQL Source: https://context7.com/asg017/sqlite-http/llms.txt The http_get table-valued function performs a GET request and returns a single row containing comprehensive request and response details. This includes headers, status codes, timing data, and the remote server address, useful for detailed analysis. ```sql -- Get full request details SELECT request_url, response_status, response_status_code, length(response_body) AS body_length, remote_address FROM http_get('https://google.com'); /* ┌────────────────────┬─────────────────┬──────────────────────┬─────────────┬────────────────────┐ │ request_url │ response_status │ response_status_code │ body_length │ remote_address │ ├────────────────────┼─────────────────┼──────────────────────┼─────────────┼────────────────────┤ │ https://google.com │ 200 OK │ 200 │ 14043 │ 142.250.80.46:443 │ └────────────────────┴─────────────────┴──────────────────────┴─────────────┴────────────────────┘ */ -- Access timing information for performance analysis SELECT request_url, json_extract(timings, '$.start') AS started, json_extract(timings, '$.dns_start') AS dns_start, json_extract(timings, '$.dns_end') AS dns_end, json_extract(timings, '$.first_byte') AS first_byte FROM http_get('https://api.github.com/'); ``` -------------------------------- ### Get sqlite-http Debug Information Source: https://github.com/asg017/sqlite-http/blob/main/docs.md Returns detailed debug information about the `sqlite-http` library, including its version, commit hash, runtime environment, and build date. The output format is subject to change. ```sql select http_debug(); /* Version: "v0.0.0" Commit: 85445c7b9d539e2626731275da6496d96d6dbb05 Runtime: go1.17 darwin/amd64 Date: 2021-11-17T16:20:06Z-0800 */ ``` -------------------------------- ### Get HTTP Extension Debug Information Source: https://context7.com/asg017/sqlite-http/llms.txt Returns comprehensive debug information about the sqlite-http extension, including its version, commit hash, runtime environment, and build date. ```sql SELECT http_debug(); /* Version: v0.1.1 Commit: 85445c7b9d539e2626731275da6496d96d6dbb05 Runtime: go1.17 darwin/amd64 Date: 2021-11-17T16:20:06Z-0800 */ ``` -------------------------------- ### Get sqlite-http Version Source: https://github.com/asg017/sqlite-http/blob/main/docs.md Returns the current version of the `sqlite-http` library. This is a simple utility function with no arguments. ```sql SELECT http_version(); ``` -------------------------------- ### Get HTTP Extension Version Source: https://context7.com/asg017/sqlite-http/llms.txt Retrieves the current version string of the sqlite-http extension. This is useful for compatibility checks and debugging. ```sql SELECT http_version(); -- 'v0.1.1' ``` -------------------------------- ### Making HTTP Requests Source: https://github.com/asg017/sqlite-http/blob/main/docs.md Functions for making various types of HTTP requests, including GET, POST, and general methods. These functions can return all request contents, only the body, or only the headers. ```APIDOC ## HTTP Request Functions ### Description These functions allow you to make HTTP requests and retrieve different parts of the response, such as all contents, just the body, or just the headers. ### Functions - `http_get(_url, [headers], [cookies]_)`: Requests all contents from a URL using the GET method. - `http_post(_url, [headers], [body], [cookies]_)`: Requests all contents from a URL using the POST method. - `http_do(_method, url, [headers], [body], [cookies]_)`: Requests all contents from a URL using a specified HTTP method. - `http_get_body(_url, [headers], [cookies]_)`: Requests only the body content from a URL using the GET method. - `http_post_body(_url, [headers], [body], [cookies]_)`: Requests only the body content from a URL using the POST method. - `http_do_body(_method, url, [headers], [body], [cookies]_)`: Requests only the body content from a URL using a specified HTTP method. - `http_get_headers(_url, [headers], [cookies]_)`: Requests only the header content from a URL using the GET method. - `http_post_headers(_url, [headers], [body], [cookies]_)`: Requests only the header content from a URL using the POST method. - `http_do_headers(_method, url, [headers], [body], [cookies]_)`: Requests only the header content from a URL using a specified HTTP method. ### Parameters - `_url` (string): The URL to make the request to. - `[headers]` (table): Optional. Headers to include in the request, created using `http_headers()`. - `[cookies]` (table): Optional. Cookies to include in the request, created using `http_cookies()`. - `[body]` (string): Optional. The body content for POST or PUT requests. - `_method` (string): The HTTP method to use (e.g., 'PUT', 'DELETE'). ### Request Example (Full Content) ```sql SELECT http_get('http://example.com'); ``` ### Request Example (Body Only) ```sql SELECT http_get_body('http://example.com'); ``` ### Request Example (Headers Only) ```sql SELECT http_get_headers('http://example.com'); ``` ### Response Example (Full Content) ```json { "headers": { "Content-Type": "application/json" }, "body": "{\"message\": \"Hello, world!\"}", "timings": { "connect": 10, "send": 5, "wait": 100, "receive": 20 }, "request": { "method": "GET", "url": "http://example.com" } } ``` ### Response Example (Body Only) ```json { "message": "Hello, world!" } ``` ### Response Example (Headers Only) ```json { "Content-Type": "application/json" } ``` ``` -------------------------------- ### Load sqlite-http Extension with better-sqlite3 Source: https://github.com/asg017/sqlite-http/blob/main/npm/sqlite-http/README.md Demonstrates loading the sqlite-http extension into a better-sqlite3 database instance and querying the HTTP version. Requires the 'better-sqlite3' and 'sqlite-http' packages. ```javascript import Database from "better-sqlite3"; import * as sqlite_http from "sqlite-http"; const db = new Database(":memory:"); db.loadExtension(sqlite_http.getLoadablePath()); const version = db.prepare("select http_version()").pluck().get(); console.log(version); // "v0.2.0" ``` -------------------------------- ### HTTP GET Request Source: https://github.com/asg017/sqlite-http/blob/main/docs.md The http_get table function makes an HTTP GET request to the specified URL and returns a single row containing details about the request and response. ```APIDOC ## GET /table_function/http_get ### Description Makes an HTTP GET request to a specified URL and returns a table with request and response details. ### Method TABLE FUNCTION ### Endpoint `http_get(url, [headers], [cookies])` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```sql SELECT * FROM http_get('https://example.com'); ``` ### Response #### Success Response (Single Row Table) - **request_url** (TEXT) - URL that is requested. - **request_method** (TEXT) - HTTP method used in request (e.g., "GET"). - **request_headers** (TEXT) - Request HTTP headers, in wire format. - **request_cookies** (TEXT) - Cookies sent in request (unstable). - **request_body** (BLOB) - Body sent in request. - **response_status** (TEXT) - Status text of the response (e.g., "200 OK"). - **response_status_code** (INT) - HTTP status code of the response (e.g., 200). - **response_headers** (TEXT) - Response HTTP headers, in wire format. - **response_cookies** (TEXT) - Cookies received in response (unstable). - **response_body** (BLOB) - Body received in response. - **remote_address** (TEXT) - IP address of responding server. - **timings** (TEXT) - JSON of various event timestamps. - **meta** (TEXT) - Metadata of request (currently null). #### Response Example ```sql SELECT request_url, response_status, length(response_body) FROM http_get('https://google.com'); /* ┌────────────────────┬─────────────────┬───────────────────────┐ │ request_url │ response_status │ length(response_body) │ ├────────────────────┼─────────────────┼───────────────────────┤ │ https://google.com │ 200 OK │ 14043 │ └────────────────────┴─────────────────┴───────────────────────┘ */ ``` ``` -------------------------------- ### SQLite CLI Loading and Usage Source: https://context7.com/asg017/sqlite-http/llms.txt Provides instructions on how to load the sqlite-http extension directly within the SQLite command-line interface (CLI) and perform basic HTTP requests. ```sql -- Load the extension .load ./http0 -- Verify it's loaded SELECT http_version(); -- Make requests SELECT http_get_body('https://api.example.com/data'); ``` -------------------------------- ### Perform HTTP GET Request and Return Only Response Body Source: https://github.com/asg017/sqlite-http/blob/main/docs.md The http_get_body function executes a GET request to the specified URL and returns only the response body. This is useful for simple requests where only the content is needed. Optional headers and cookies can be supplied. ```sql select http_get_body('https://dog.ceo/api/breeds/image/random'); /* { "message":"https://images.dog.ceo/breeds/komondor/n02105505_3967.jpg", "status":"success" } */ ``` -------------------------------- ### Make HTTP GET Request with Body Source: https://github.com/asg017/sqlite-http/blob/main/docs.md Retrieves the body content of a URL using an HTTP GET request. It accepts the URL, optional headers, and optional cookies as arguments. This function is useful for fetching data from web resources. ```sql SELECT http_get_body( 'http://localhost:8000/data' ); ``` -------------------------------- ### Load sqlite-http Extension with node-sqlite3 Source: https://github.com/asg017/sqlite-http/blob/main/npm/sqlite-http/README.md Demonstrates loading the sqlite-http extension into a node-sqlite3 database instance and querying the HTTP version. Requires the 'sqlite3' and 'sqlite-http' packages. ```javascript import sqlite3 from "sqlite3"; import * as sqlite_http from "sqlite-http"; const db = new sqlite3.Database(":memory:"); db.loadExtension(sqlite_http.getLoadablePath()); db.get("select http_version()", (err, row) => { console.log(row); // {json_schema_version(): "v0.2.0"} }); ``` -------------------------------- ### Load sqlite_http Extension in Deno Source: https://github.com/asg017/sqlite-http/blob/main/deno/README.md Demonstrates how to load the sqlite_http extension into a Deno SQLite database using the x/sqlite3 module. It shows importing necessary modules, initializing a database, loading the extension, and querying its version. Requires network and filesystem permissions. ```javascript import { Database } from "https://deno.land/x/sqlite3@0.8.0/mod.ts"; import * as sqlite_http from "https://deno.land/x/sqlite_http@v0.1.1/mod.ts"; const db = new Database(":memory:"); db.enableLoadExtension = true; sqlite_http.load(db); const [version] = db .prepare("select http_version()") .value<[string]>()!; console.log(version); ``` -------------------------------- ### Retrieve Response Headers from GET Request (SQL) Source: https://context7.com/asg017/sqlite-http/llms.txt The `http_get_headers` function performs an HTTP GET request and returns only the response headers in their raw wire format. This is useful when you only need header information, such as caching directives or content types, without the response body. ```sql SELECT http_get_headers('https://api.github.com/'); /* Access-Control-Allow-Origin: * Cache-Control: public, max-age=60, s-maxage=60 Content-Security-Policy: default-src 'none' Content-Type: application/json; charset=utf-8 ... */ ``` -------------------------------- ### Header Utilities Source: https://context7.com/asg017/sqlite-http/llms.txt Utilities for constructing, parsing, and querying HTTP headers. ```APIDOC ## Header Utilities ### http_headers(name1, value1, ...) Constructs HTTP headers in wire format from name-value pairs. Used as input for request functions. #### Parameters * **name1, value1, ...** (TEXT) - Pairs of header name and value. ### Request Example ```sql SELECT http_headers( 'Authorization', 'Bearer my-token', 'Content-Type', 'application/json', 'X-Custom-Header', 'custom-value' ); /* Authorization: Bearer my-token Content-Type: application/json X-Custom-Header: custom-value */ ``` ### http_headers_each(headers) A table-valued function that iterates through all headers, returning each as a row with name and value columns. #### Parameters * **headers** (TEXT) - HTTP headers in wire format. ### Request Example ```sql -- Parse and filter response headers SELECT name, value FROM http_headers_each(http_get_headers('https://api.github.com/')) WHERE name LIKE 'X-%'; /* ┌────────────────────────┬────────────────────────────────────┐ │ name │ value │ ├────────────────────────┼────────────────────────────────────┤ │ X-Ratelimit-Limit │ 60 │ │ X-Ratelimit-Used │ 8 │ │ X-Content-Type-Options │ nosniff │ │ X-Github-Media-Type │ github.v3; format=json │ │ X-Frame-Options │ deny │ └────────────────────────┴────────────────────────────────────┘ */ ``` ### http_headers_has(headers, name) Returns 1 if the header exists, 0 otherwise. Header name lookup is case-insensitive. #### Parameters * **headers** (TEXT) - HTTP headers in wire format. * **name** (TEXT) - The name of the header to check for. ### Request Example ```sql SELECT http_headers_has( http_get_headers('https://api.github.com/'), 'Content-Type' ); -- 1 SELECT http_headers_has( http_headers('X-Foo', 'bar'), 'x-foo' -- case-insensitive ); -- 1 ``` ### http_headers_get(headers, name) Returns the value of the first matching header, or NULL if not found. Header name lookup is case-insensitive. #### Parameters * **headers** (TEXT) - HTTP headers in wire format. * **name** (TEXT) - The name of the header to retrieve. ### Request Example ```sql SELECT http_headers_get( http_get_headers('https://api.github.com/'), 'Content-Type' ); -- 'application/json; charset=utf-8' -- Get rate limit information from GitHub API SELECT http_headers_get( http_get_headers('https://api.github.com/'), 'X-Ratelimit-Remaining' ) AS remaining_requests; ``` ### http_headers_date(value) Parses RFC5322 date format (common in HTTP headers) to SQLite's ISO8601 format. #### Parameters * **value** (TEXT) - The date string in RFC5322 format. ### Request Example ```sql SELECT http_headers_date('Sun, 06 Nov 1994 08:49:37 GMT'); -- '1994-11-06 08:49:37' -- Parse Expires header from response SELECT http_headers_date( http_headers_get( http_get_headers('https://example.com/resource'), 'Expires' ) ) AS expires_at; ``` ``` -------------------------------- ### HTTP Headers Manipulation Source: https://github.com/asg017/sqlite-http/blob/main/docs.md Functions for creating, checking, getting, and iterating over HTTP headers. ```APIDOC ## HTTP Headers Functions ### Description Utilities for creating and manipulating HTTP headers in wire format. ### Functions - `http_headers(_name1, value1, ..._)`: Creates a table of HTTP headers from key-value pairs. - `http_headers_has(_headers, name_)`: Checks if a header with the given name exists. - `http_headers_get(_headers, name_)`: Retrieves the value of a specific header. - `http_headers_each(_headers_)`: Returns a table of all headers, one row per header. ### Parameters - `_headers` (table): A table of headers (output from `http_headers`). - `name` (string): The name of the header to check or retrieve. - `name1`, `value1`, ...: Key-value pairs for creating headers. ### Request Example (Create Headers) ```sql SELECT http_headers( 'Content-Type', 'application/json', 'Accept', 'application/json' ); ``` ### Request Example (Check Header) ```sql SELECT http_headers_has( http_headers('Content-Type', 'application/json'), 'Content-Type' ); ``` ### Request Example (Get Header) ```sql SELECT http_headers_get( http_headers('Content-Type', 'application/json'), 'Content-Type' ); ``` ### Request Example (Iterate Headers) ```sql SELECT * FROM http_headers_each(http_headers('Content-Type', 'application/json')); ``` ### Response Example (Create Headers) ``` -- Returns a table representing headers ``` ### Response Example (Check Header) ``` 1 ``` ### Response Example (Get Header) ``` application/json ``` ### Response Example (Iterate Headers) ``` -- Returns rows like: { name = 'Content-Type', value = 'application/json' } ``` ``` -------------------------------- ### Deno Permissions for sqlite_http Source: https://github.com/asg017/sqlite-http/blob/main/deno/README.md Specifies the necessary Deno permissions to run code that utilizes the x/sqlite_http module. It indicates that `--allow-ffi` and `--unstable` are required, and suggests using `--allow-all` for convenience. ```bash deno run -A --unstable ``` -------------------------------- ### Get sqlite-http Version Source: https://github.com/asg017/sqlite-http/blob/main/docs.md Retrieves the version string of the `sqlite-http` library. This function is modeled after the standard SQLite `sqlite_version()` function. ```sql select http_version(); -- "v0.0.0" ``` -------------------------------- ### getLoadablePath() Source: https://github.com/asg017/sqlite-http/blob/main/npm/sqlite-http/README.md Retrieves the full path to the sqlite-http loadable extension. ```APIDOC ## `getLoadablePath()` ### Description Returns the full path to where the `sqlite-http` extension is installed. This path can be directly used with the `.loadExtension()` method of SQLite clients like `better-sqlite3` and `node-sqlite3`. ### Method `getLoadablePath()` ### Endpoint N/A (Node.js function) ### Parameters No parameters. ### Request Example ```js import * as sqlite_http from "sqlite-http"; try { const extensionPath = sqlite_http.getLoadablePath(); console.log(extensionPath); } catch (error) { console.error("Error getting loadable path:", error.message); } ``` ### Response #### Success Response (200) - **extensionPath** (string) - The absolute path to the compiled `sqlite-http` extension file. #### Response Example ``` "/path/to/your/node_modules/sqlite-http/lib/http0.so" ``` ### Error Handling This function throws an `Error` if: 1. `sqlite-http` is installed on an unsupported platform. 2. The platform-specific optional dependency is not installed (e.g., if `--no-optional` flag was used during npm install). 3. The compiled extension is incompatible with the SQLite connection for reasons like missing system packages or glib versions. ``` -------------------------------- ### HTTP Version Information Source: https://context7.com/asg017/sqlite-http/llms.txt Retrieves the version string of the sqlite-http extension. ```APIDOC ## Meta Function: Version ### Description Returns the version string of the currently loaded sqlite-http extension. ### Method N/A (Meta function) ### Endpoint N/A ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```sql SELECT http_version(); ``` ### Response #### Success Response (200) - **version** (string) - The version string of the extension. #### Response Example ```json { "version": "v0.1.1" } ``` ``` -------------------------------- ### Load sqlite-http Extension in SQLite CLI Source: https://github.com/asg017/sqlite-http/blob/main/README.md Demonstrates loading the sqlite-http extension dynamically into the SQLite command-line interface (CLI). This allows direct SQL queries to use HTTP functions. ```sql .load ./http0 select http_version(); -- v0.0.1 ``` -------------------------------- ### Get Header Value Source: https://github.com/asg017/sqlite-http/blob/main/docs.md Retrieves the value of a specific header from a set of headers. It requires the headers object and the name of the header whose value is sought. ```sql SELECT http_headers_get( http_headers('X-API-Key', 'abcdef123'), 'X-API-Key' ); ``` -------------------------------- ### Perform Custom HTTP Method Request with Full Response Metadata (SQL) Source: https://context7.com/asg017/sqlite-http/llms.txt The `http_do` function allows for custom HTTP methods (e.g., PUT, DELETE) and returns full request/response metadata. It's useful for interacting with APIs that require specific HTTP verbs and for analyzing request timings. ```sql -- Custom PUT request with response analysis SELECT request_method, response_status_code, json_extract(timings, '$.start') AS start_time, json_extract(timings, '$.first_byte') AS response_time FROM http_do( 'PUT', 'https://httpbin.org/put', http_headers('Content-Type', 'application/json'), '{"id": 1, "name": "updated"}' ); ``` -------------------------------- ### HTTP Rate Limiting Configuration Source: https://context7.com/asg017/sqlite-http/llms.txt Configures a minimum delay between HTTP requests to respect API rate limits. ```APIDOC ## Configuration: Rate Limiting ### Description Sets a minimum delay between consecutive HTTP requests in milliseconds. This is crucial for adhering to API rate limits and preventing excessive load on external services. ### Method N/A (Configuration function) ### Endpoint N/A ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```sql -- Set a 250ms delay between requests SELECT http_rate_limit(250); -- Subsequent requests will automatically pause for 250ms SELECT http_get_body('https://api.example.com/item/1'); SELECT http_get_body('https://api.example.com/item/2'); SELECT http_get_body('https://api.example.com/item/3'); ``` ### Response #### Success Response (200) This function does not return data but configures the behavior of subsequent requests. #### Response Example N/A ``` -------------------------------- ### Python Usage of sqlite-http Source: https://context7.com/asg017/sqlite-http/llms.txt Demonstrates how to load and use the sqlite-http extension within a Python application using the `sqlite3` module. It shows both standard HTTP access and a secure 'no-network' mode. ```python import sqlite3 import sqlite_http # Standard connection with full HTTP capabilities conn = sqlite3.connect(':memory:') conn.enable_load_extension(True) sqlite_http.load(conn) result = conn.execute("SELECT http_get_body('https://api.github.com/')").fetchone() print(result[0]) # No-network mode (only utility functions, no HTTP requests) conn2 = sqlite3.connect(':memory:') conn2.enable_load_extension(True) sqlite_http.load_no_network(conn2) # This works: headers = conn2.execute("SELECT http_headers('X-Foo', 'bar')").fetchone() # This would error in no-network mode: # conn2.execute("SELECT http_get_body('https://example.com')") ``` -------------------------------- ### Create HTTP Headers Source: https://github.com/asg017/sqlite-http/blob/main/docs.md Creates a set of HTTP headers in the format expected by `sqlite-http` functions. Headers are provided as alternating name-value pairs. ```sql SELECT http_headers( 'Content-Type', 'application/json', 'Accept', 'application/json' ); ``` -------------------------------- ### HTTP Debug Information Source: https://context7.com/asg017/sqlite-http/llms.txt Retrieves detailed debug information about the sqlite-http extension. ```APIDOC ## Meta Function: Debug Information ### Description Returns detailed debug information about the sqlite-http extension, including its version, commit hash, Go runtime details, and build date. ### Method N/A (Meta function) ### Endpoint N/A ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```sql SELECT http_debug(); ``` ### Response #### Success Response (200) - **debug_info** (string) - A multi-line string containing debug details. #### Response Example ```text Version: v0.1.1 Commit: 85445c7b9d539e2626731275da6496d96d6dbb05 Runtime: go1.17 darwin/amd64 Date: 2021-11-17T16:20:06Z-0800 ``` ``` -------------------------------- ### Custom Method Requests Source: https://context7.com/asg017/sqlite-http/llms.txt Functions for making requests with custom HTTP methods and retrieving full response metadata. ```APIDOC ## Custom Method Requests ### http_do(method, url, [headers], [body], [cookies]) A table-valued function for custom HTTP methods with full response metadata. #### Parameters * **method** (TEXT) - The HTTP method (e.g., 'PUT', 'DELETE', 'OPTIONS'). * **url** (TEXT) - The URL to send the request to. * **headers** (TEXT, Optional) - HTTP headers in wire format, constructed using `http_headers()`. * **body** (TEXT, Optional) - The request body. * **cookies** (TEXT, Optional) - Cookies in JSON format, constructed using `http_cookies()`. ### Request Example ```sql -- Custom PUT request with response analysis SELECT request_method, response_status_code, json_extract(timings, '$.start') AS start_time, json_extract(timings, '$.first_byte') AS response_time FROM http_do( 'PUT', 'https://httpbin.org/put', http_headers('Content-Type', 'application/json'), '{"id": 1, "name": "updated"}' ); ``` ### Response #### Success Response (200) * **request_method** (TEXT) - The HTTP method used for the request. * **response_status_code** (INTEGER) - The HTTP status code of the response. * **timings** (TEXT) - JSON object containing timing information for the request. * **response_body** (TEXT) - The response body. #### Response Example ```json { "request_method": "PUT", "response_status_code": 200, "timings": { "send": 0.1, "wait": 1.2, "receive": 0.3, "start": 1.3 }, "response_body": "{\"json\": {\"id\": 1, \"name\": \"updated\"}, ...}" } ``` ``` -------------------------------- ### Perform Generic HTTP Request and Return Full Response Source: https://github.com/asg017/sqlite-http/blob/main/docs.md The http_do function allows for performing HTTP requests with a specified method (e.g., DELETE, PUT, POST) to a given URL. It returns the complete HTTP response. Optional headers, body, and cookies can be provided. ```sql select * from http_do('delete', 'http://httpbin.org/delete'); ``` -------------------------------- ### Make Generic HTTP Request with Headers Source: https://github.com/asg017/sqlite-http/blob/main/docs.md Executes a generic HTTP request with a specified method and returns only the response headers. Parameters include the method, URL, optional headers, optional body, and optional cookies. ```sql SELECT http_do_headers( 'DELETE', 'http://localhost:8000/item/5' ); ``` -------------------------------- ### POST Requests Source: https://context7.com/asg017/sqlite-http/llms.txt Functions for making POST requests and retrieving full response metadata. ```APIDOC ## POST Requests ### http_post(url, [headers], [body], [cookies]) A table-valued function for POST requests that returns complete request/response metadata. #### Parameters * **url** (TEXT) - The URL to send the POST request to. * **headers** (TEXT, Optional) - HTTP headers in wire format, constructed using `http_headers()`. * **body** (TEXT, Optional) - The request body. * **cookies** (TEXT, Optional) - Cookies in JSON format, constructed using `http_cookies()`. ### Request Example ```sql -- POST with full response details SELECT request_method, response_status_code, response_headers, response_body FROM http_post( 'https://httpbin.org/post', http_headers('Content-Type', 'application/json'), '{"action": "create", "data": "test"}' ); -- Handle non-200 responses gracefully SELECT iif( response_status_code NOT BETWEEN 200 AND 299, 'Error: ' || response_status, 'Success' ) AS status, response_body FROM http_post('https://httpbin.org/status/503'); ``` ### Response #### Success Response (200) * **request_method** (TEXT) - The HTTP method used for the request. * **response_status_code** (INTEGER) - The HTTP status code of the response. * **response_headers** (TEXT) - The response headers in wire format. * **response_body** (TEXT) - The response body. #### Response Example ```json { "request_method": "POST", "response_status_code": 200, "response_headers": "HTTP/1.1 200 OK\r\nContent-Type: application/json\r\n...", "response_body": "{\"json": {\"action\": \"create\", \"data\": \"test\"}, ...}" } ``` ``` -------------------------------- ### HTTP Timeout Configuration Source: https://context7.com/asg017/sqlite-http/llms.txt Sets the maximum duration for HTTP requests before they time out. ```APIDOC ## Configuration: Timeout Setting ### Description Sets the maximum time, in milliseconds, that the extension will wait for an HTTP request to complete. The default timeout is 5000 milliseconds (5 seconds). ### Method N/A (Configuration function) ### Endpoint N/A ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```sql -- Set a 10-second timeout (10000 milliseconds) SELECT http_timeout_set(10000); -- Set a shorter 2-second timeout for a potentially slow request SELECT http_timeout_set(2000); SELECT http_get_body('https://slow-api.example.com/data'); -- This request will error if it takes longer than 2 seconds to complete. ``` ### Response #### Success Response (200) This function does not return data but configures the behavior of subsequent requests. #### Response Example N/A ``` -------------------------------- ### Load sqlite-http Extension in Node.js Source: https://github.com/asg017/sqlite-http/blob/main/README.md Illustrates loading the sqlite-http extension using the better-sqlite3 library in Node.js. This allows Node.js applications to leverage HTTP capabilities within SQLite. ```javascript const Database = require("better-sqlite3"); const db = new Database(":memory:"); db.loadExtension("./http0"); console.log(db.prepare("select http_version() է").get()); // { 'http_version()': 'v0.0.1' } ```