Skip to content

Cookies

Ravi Teja Gudapati edited this page Jan 9, 2019 · 5 revisions

Reading cookies from request

Cookies sent by the client can be read from the request using cookies member of Context object. It exposes cookies as a Map of cookie name to Cookie.

String token = ctx.cookies['token']?.value;

Setting cookie to response

A new cookie can be set or an old cookie updated using cookies member of Response object. It exposes cookies as a list of Cookie.

ctx.response.cookies.add(Cookies('token', token));

NOTE: Request cookies and response cookies are not same thing. Request cookies are read from the request header Cookie sent by the client. Response cookies are list of Cookies used to set new cookies or update existing cookies using the Set-Cookie response header. The client reads the Set-Cookie header, updates its cookie store accordingly and sends its cookies using Cookie request header in the following requests. More information can be found in Mozilla developer site.

Removing a cookie

Due to how cookies work, it is not possible to remove cookies directly. One must either set the cookie to empty or use expires to remove the cookie. deleteCookie member of Response class does it for you.

For example, to remove a cookie named 'token':

ctx.response.deleteCookie('token');

Basics

Serialization

Forms

Sessions

Authentication

  • Basic authentication
  • Form authentication
  • JSON authentication
  • Authorization
  • OAuth

Database

Security

Real time

  • Server sent events (SSE)
  • Websockets

Deployment

  • systemd
  • Docker
  • AppEngine

API Documentation

Clone this wiki locally