@caviajs/http-cookie
v1.0.6
Published
a micro framework for node.js
Downloads
18
Readme
Introduction
An HTTP cookie is a small piece of data stored by the user's browser. Cookies were designed to be a reliable mechanism for websites to remember stateful information. When the user visits the website again, the cookie is automatically sent with the request.
Usage
Installation
npm install @caviajs/http-cookie --save
Request cookies
Parse cookies
import { HttpCookie } from '@caviajs/http-cookie';
router
.route({
handler: (request, response, next) => {
const cookies = HttpCookie.parse(request);
// cookies...
},
/* ... */
});
Response cookies
Set cookie
import { HttpCookie } from '@caviajs/http-cookie';
router
.route({
handler: (request, response, next) => {
HttpCookie.set(response, 'name', 'value', {
/*
domain?: string;
expires?: Date;
httpOnly?: boolean;
maxAge?: number;
path?: string;
sameSite?: 'Lax' | 'Strict' | 'None';
secure?: boolean;
*/
});
},
/* ... */
});
Delete cookie
import { HttpCookie } from '@caviajs/http-cookie';
router
.route({
handler: (request, response, next) => {
HttpCookie.delete(response, 'name', {
/*
domain?: string;
httpOnly?: boolean;
path?: string;
sameSite?: 'Lax' | 'Strict' | 'None';
secure?: boolean;
*/
});
},
/* ... */
});