GET

GET allows one to create a server function which is accessed via an HTTP GET request. When this function is called, the arguments are serialized into the url, thus allowing the use of HTTP cache-control headers.

Usage

Example with streaming promise and a 60 second cache life

tsx
import { json } from "@solidjs/router";
import { GET } from "@solidjs/start";
 
const hello = GET(async (name: string) => {
"use server";
return json(
{ hello: new Promise<string>(r => setTimeout(() => r(name), 1000)) },
{ headers: { "cache-control": "max-age=60" } }
);
});
tsx
import { json } from "@solidjs/router";
import { GET } from "@solidjs/start";
 
const hello = GET(async (name: string) => {
"use server";
return json(
{ hello: new Promise<string>(r => setTimeout(() => r(name), 1000)) },
{ headers: { "cache-control": "max-age=60" } }
);
});