-
Notifications
You must be signed in to change notification settings - Fork 35
Cookies
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;
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.
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
- Route handler
- Path matching
- Path parameters
- Query parameters
- Serving static files
- Cookies
- Controller
- Parameter binding
- Hot reload
Serialization
Forms
Sessions
Authentication
- Basic authentication
- Form authentication
- JSON authentication
- Authorization
- OAuth
- MongoDb
- PostgreSQL
- MySQL
- Establish connection
- ORM
- Server sent events (SSE)
- Websockets
- systemd
- Docker
- AppEngine