npm

Does your artifact manager get in the way? Join us on Oct. 8 at 10am PT, to discuss how npm can help.Sign up »

koa-cookie

1.0.0 • Public • Published

koa-cookie

Cookie parser middleware for koa. Can also be used with koa-router.

Install

npm install koa-cookie --save

Example

import Koa from 'koa';
import cookie from 'koa-cookie';
 
const app = Koa();
app.use(cookie());
 
app.use(async function (ctx, next) {
  const cookies = ctx.cookie;
  /*
    if cookies sent are of the form: 'name=abc; age=20; token = xyz;'
    Then ctx.cookie is an object of the form:
    {
      name: 'abc',
      age: '20',
      token: 'xyz'
    }
  */
});
 

Example with koa-router

var app = require('koa')();
var cookie = require('koa-cookie');
var router = require('koa-router')();
 
router.use(cookie());
 
router.get('/', async (context) => {
  const cookies = context.cookie;
  /*
    if cookies sent are of the form: 'name=abc; age=20; token = xyz;'
    Then ctx.cookie is an object of the form:
    {
      name: 'abc',
      age: '20',
      token: 'xyz'
    }
  */
});
 
app
  .use(router.routes())
  .use(router.allowedMethods());

install

npm i koa-cookie

Downloadsweekly downloads

4,142

version

1.0.0

license

ISC

homepage

github.com

repository

Gitgithub

last publish

collaborators

  • avatar
Report a vulnerability