Drivers
HTTP
Use a remote HTTP/HTTPS endpoint as data storage.
Usage
Supports built-in http server methods.
This driver implements meta for each key including mtime
(last modified time) and status
from HTTP headers by making a HEAD
request.
import { createStorage } from "unstorage";
import httpDriver from "unstorage/drivers/http";
const storage = createStorage({
driver: httpDriver({ base: "http://cdn.com" }),
});
Options:
base
: Base URL for urls (required)headers
: Custom headers to send on all requests
Supported HTTP Methods:
getItem
: Maps to httpGET
. Returns deserialized value if response is okhasItem
: Maps to httpHEAD
. Returnstrue
if response is ok (200)getMeta
: Maps to httpHEAD
(headers:last-modified
=>mtime
,x-ttl
=>ttl
)setItem
: Maps to httpPUT
. Sends serialized value using body (ttl
option will be sent asx-ttl
header).removeItem
: Maps toDELETE
clear
: Not supported
Transaction Options:
headers
: Custom headers to be sent on each operation (getItem
,setItem
, etc)ttl
: Customttl
(in seconds) for supported drivers. Will be mapped tox-ttl
http header.