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(alias) function json<T>(data: T, init?: RouterResponseInit): T
import json
} from "@solidjs/router"; import { GET(alias) function GET<T extends (...args: any[]) => any>(fn: T): (...args: Parameters<T>) => ReturnType<T>
import GET
} from "@solidjs/start";
const helloconst hello: (name: string) => Promise<{
hello: Promise<string>;
}>
= GET(alias) GET<(name: string) => Promise<{
hello: Promise<string>;
}>>(fn: (name: string) => Promise<{
hello: Promise<string>;
}>): (name: string) => Promise<{
hello: Promise<string>;
}>
import GET
(async (name: string) => { "use server";
return json(alias) json<{
hello: Promise<string>;
}>(data: {
hello: Promise<string>;
}, init?: RouterResponseInit | undefined): {
hello: Promise<string>;
}
import json
( { hello(property) hello: Promise<string>
: new PromiseCreates a new Promise.
var Promise: PromiseConstructor
new <string>(executor: (resolve: (value: string | PromiseLike<string>) => void, reject: (reason?: any) => void) => void) => Promise<string>
<string>(r(parameter) r: (value: string | PromiseLike<string>) => void
=> setTimeout[MDN Reference](https://developer.mozilla.org/docs/Web/API/setTimeout)
function setTimeout(handler: TimerHandler, timeout?: number | undefined, ...arguments: any[]): number
(() => r(parameter) r: (value: string | PromiseLike<string>) => void
(name), 1000)) }, { headers(property) headers?: HeadersInit | undefined
: { "cache-control": "max-age=60" } } );
});
tsx
import { json(alias) function json<T>(data: T, init?: RouterResponseInit): T
import json
} from "@solidjs/router"; import { GET(alias) function GET<T extends (...args: any[]) => any>(fn: T): (...args: Parameters<T>) => ReturnType<T>
import GET
} from "@solidjs/start";
const helloconst hello: (name: string) => Promise<{
hello: Promise<string>;
}>
= GET(alias) GET<(name: string) => Promise<{
hello: Promise<string>;
}>>(fn: (name: string) => Promise<{
hello: Promise<string>;
}>): (name: string) => Promise<{
hello: Promise<string>;
}>
import GET
(async (name: string) => { "use server";
return json(alias) json<{
hello: Promise<string>;
}>(data: {
hello: Promise<string>;
}, init?: RouterResponseInit | undefined): {
hello: Promise<string>;
}
import json
( { hello(property) hello: Promise<string>
: new PromiseCreates a new Promise.
var Promise: PromiseConstructor
new <string>(executor: (resolve: (value: string | PromiseLike<string>) => void, reject: (reason?: any) => void) => void) => Promise<string>
<string>(r(parameter) r: (value: string | PromiseLike<string>) => void
=> setTimeout[MDN Reference](https://developer.mozilla.org/docs/Web/API/setTimeout)
function setTimeout(handler: TimerHandler, timeout?: number | undefined, ...arguments: any[]): number
(() => r(parameter) r: (value: string | PromiseLike<string>) => void
(name), 1000)) }, { headers(property) headers?: HeadersInit | undefined
: { "cache-control": "max-age=60" } } );
});