setCookie(name, value, [options]) Last updated: 20. Oct 2026
API only function
Sets a cookie on the response. Available in API scripts and the site router — pages are rendered once and shared, so they cannot set cookies.
Parameters
| Name | Type | Description |
|---|---|---|
| name | string | The cookie name: letters, digits, |
| value | string | The value, stored as text. Name and value together at most 4096 bytes. |
| options (optional) | object |
|
Returns
Nothing. The cookie is sent with the response — in the site router with every result, also a redirect or an answer such as route.json. Secure is set automatically on HTTPS. Setting the same name twice in one request keeps the last value.
SameSite=Lax is the default because a sign-in that returns from another site (OAuth) needs the cookie on that first request. Use "Strict" for cookies that never take part in a flow across sites.
Example
Code example (JS)
JS is normal JavaScript either running in the browser or on the Docly™ server.// Remember a choice for a year
docly.setCookie("theme", "dark", { maxAge: 365 * 24 * 3600 });
// A short-lived value for a sign-in round trip (see The site router)
docly.setCookie("oauth_state", guid(), { maxAge: 600 });
// Delete it again
docly.setCookie("oauth_state", "", { maxAge: 0 });