Cookies
To read/write cookies you can access the set()
and get()
methods on the Context.cookies
object:
// cookies.ts
import { Application, HTTPResponse, HTTPStatus, Router } from 'jsr:@sequoia/sequoia'
const app = new Application()
const router = new Router()
router.GET('/', (context) => {
console.log(context.cookies.get('Hello')?.value)
context.cookies.set('Hello', 'World')
return new HTTPResponse({
type: 'application/json',
status: HTTPStatus.SUCCESS,
body: { ok: true },
})
})
app.useRouter(router)
await app.listen({ port: 8000 })
Run it with deno run --allow-net cookies.ts
To clear the cookie on the response, use delete()
method:
// clear-cookies.ts
import { Application, HTTPResponse, HTTPStatus, Router } from 'jsr:@sequoia/sequoia'
const app = new Application()
const router = new Router()
router.GET('/clear-cookies', (context) => {
if (context.cookies.get('Hello')) {
context.cookies.delete('Hello')
}
return new HTTPResponse({
type: 'application/json',
status: HTTPStatus.SUCCESS,
body: { ok: true },
})
})
app.useRouter(router)
await app.listen({ port: 8000 })
Run it with deno run --allow-net clear-cookies.ts