prismy-cookie
TypeScript icon, indicating that this package has built-in type declarations

3.0.0 • Public • Published

prismy-cookie

🍪 Cookie for prismy.

Build Status codecov NPM download Language grade: JavaScript

Installation

npm i prismy-cookie

Usage

import {
  prismy,
  res,
  createUrlEncodedBodySelector,
  methodSelector,
  contextSelector,
  Context
} from 'prismy'
import {
  createCookiesSelector,
  ParsedCookies,
  appendCookie
} from 'prismy-cookie'

const urlEncodedBodySelector = createUrlEncodedBodySelector()
const cookiesSelector = createCookiesSelector()
const handler = prismy(
  [methodSelector, cookiesSelector, contextSelector],
  async (method, cookies, context) => {
    if (method === 'POST') {
      const { message } = await urlEncodedBodySelector(context)

      return appendCookie(res('OK!'), ['message', message as string])
    }

    return res(cookies.message)
  }
)

export default prismy(handler)

License

MIT

Readme

Keywords

Package Sidebar

Install

npm i prismy-cookie

Weekly Downloads

14

Version

3.0.0

License

MIT

Unpacked Size

6.92 kB

Total Files

5

Last publish

Collaborators

  • rokt33r
  • rohjs