prismy-cookie
v3.0.0
Published
:cookie: Cookie for prismy
Downloads
11
Readme
prismy-cookie
:cookie: Cookie for prismy.
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