Skip to main content

Response

The response http server.

...// example with status and headersapp.get("/hello", ({ response }) => {    return response.status(200).header({ 'name': 'value' }).send('hello');})...

Response.header#

header: (key?: object | string | undefined, value?: any) => HttpResponse | string | Headers;

...
// key and valueresponse.header("key1", "value1");
// with objectresponse.header({ "key2": "value2" });
// multiple headerresponse.header({    "key3": "value3",    "key4": "value4"});
// get headerconsole.log(response.header());// => Headers {//         "key1":"value1",//         "key2":"value2",//         "key3":"value3",//         "key4":"value4",//     }
// get header by keyconsole.log(response.header("key1"));// => value1
// delete key1response.header().delete("key1");console.log(response.header());// => Headers {//         "key2":"value2",//         "key3":"value3",//         "key4":"value4",//     }
// convert to json objectconsole.log(Object.fromEntries(response.header().entries()));// => {//       "key2":"value2",//       "key3":"value3",//       "key4":"value4",//    }
// reset headerresponseInit.headers = void 0;
console.log(response.header());// => Headers { }

Response.type#

Shorthand for response.header("Content-Type", yourContentType);

Response.status#

status: (code?: number | undefined) => HttpResponse | number;

// set statusresponse.status(201);
// get statusconsole.log(response.status());// => 201

Response.send#

send: (body?: BodyInit | { [k: string]: any } | null) => Promise<void>;

Response.json#

json: (body: { [k: string]: any } | null) => Promise<void>;

Response.redirect#

redirect: (path: string, status?: number) => Promise<void>;

Response.cookie#

...response.cookie("key", "value", {    HttpOnly: true,    maxAge: 60 * 60,    // encode value    encode: true})...

Type Cookie

type Cookie = {  expires?: Date;  maxAge?: number;  domain?: string;  path?: string;  secure?: boolean;  httpOnly?: boolean;  sameSite?: "Strict" | "Lax" | "None";  other?: string[];  encode?: boolean;};