Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/varunpal/koa-cookie
Cookie parser middleware for koa
https://github.com/varunpal/koa-cookie
Last synced: 26 days ago
JSON representation
Cookie parser middleware for koa
- Host: GitHub
- URL: https://github.com/varunpal/koa-cookie
- Owner: varunpal
- Created: 2016-08-24T09:19:15.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2018-06-19T10:56:45.000Z (over 6 years ago)
- Last Synced: 2024-11-09T08:47:26.341Z (about 1 month ago)
- Language: JavaScript
- Size: 1.95 KB
- Stars: 20
- Watchers: 2
- Forks: 3
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
- awesome-koa - koa-cookie - Cookie解析中间件。 ![](https://img.shields.io/github/stars/varunpal/koa-cookie.svg?style=social&label=Star) ![](https://img.shields.io/npm/dm/koa-cookie.svg?style=flat-square) (仓库 / 中间件)
README
# koa-cookie
Cookie parser middleware for koa.
Can also be used with [koa-router](https://www.npmjs.com/package/koa-router).## Install
```node
npm install koa-cookie --save
```### Example
```javascript
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
```javascript
var app = require('koa')();
var cookie = require('koa-cookie');
var router = require('koa-router')();router.use(cookie.default());
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());
```