Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/cupcakearmy/koa-cookie
Koa Cookie Utility
https://github.com/cupcakearmy/koa-cookie
cookie cookie-parser cookies koa koa-cookie koa-middleware parse
Last synced: 4 months ago
JSON representation
Koa Cookie Utility
- Host: GitHub
- URL: https://github.com/cupcakearmy/koa-cookie
- Owner: cupcakearmy
- License: mit
- Archived: true
- Created: 2017-08-18T15:58:45.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2018-02-25T13:09:17.000Z (almost 7 years ago)
- Last Synced: 2024-09-26T16:41:01.267Z (4 months ago)
- Topics: cookie, cookie-parser, cookies, koa, koa-cookie, koa-middleware, parse
- Language: JavaScript
- Size: 8.79 KB
- Stars: 1
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# koa-cookie
[![npm](https://img.shields.io/npm/v/cca-koa-cookie.svg)](https://www.npmjs.com/package/cca-koa-cookie)
[![npm](https://img.shields.io/npm/dt/cca-koa-cookie.svg)]()
[![npm](https://img.shields.io/npm/l/cca-koa-cookie.svg)]()
[![Travis](https://img.shields.io/travis/CupCakeArmy/koa-cookie.svg)]()Lightweight Koa-Middleware for Cookies
### Install
```bash
npm install cca-koa-cookie --save
```### QA
If you have questions:
[![Join the chat at https://gitter.im/cupcakearmy/koa-cookie](https://badges.gitter.im/cupcakearmy/koa-cookie.svg)](https://gitter.im/cupcakearmy/koa-cookie?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
### Complete Example
```javascript
const
Koa = require('koa'),
cookie = require('cca-koa-cookie'),
router = require('cca-koa-router')const
app = new Koa(),
port = 3000app.use(cookie)
app.use(router({}, _ => {
_.get('/set', (c, n) => {// Set a cookie
c.request.cookie.set({
key: 'my_id',
value: '12345678',
path: '/',
maxAge: 100,
httpOnly: true,
secure: false
})c.body = 'Cookie Set'
})_.get('/get', (c, n) => {
c.body = c.request.cookies
})
}))app.listen(port)
```## Documentation
##### ~ `cookies` Array
The Cookie Parser sets an array `ctx.request.cookies` with the cookies that where sent with the request.
###### Example
Let's say we get a cookie (`Foo=Bar;`) We can access it in the context of Koa like this: `ctx.request.cookies['Foo']` => `"bar"`##### ~ `cookie` Element
The Parser also defines a getter and setter for cookies###### Example
```javascript
// Set a cookie
ctx.request.cookie.set({
key: 'my_id',
value: '12345678',
path: '/',
maxAge: 100,
httpOnly: true,
secure: false
})
```|Options | Value |
|--------| -------------------------------|
|Key | Cookie Name |
|Value | Cookie Value |
|Path | Url Path |
|Domain | Sub or Domain |
|httpOnly| bool |
|secure | bool |
|max-age | seconds after the cookie expres|```javascript
// Get a cookie
ctx.request.cookie.get('my_id') => "12345678"
```