Sets one cookie with explicit attributes
The response includes the exact Set-Cookie header, plus a warning when SameSite=None is used without Secure.
Parameters 7
| Name | Type | Description |
|---|---|---|
namerequired | path · string | Cookie name: an RFC 6265 token, 1-64 characters. |
valuerequired | path · string | Cookie value, at most 256 characters. |
httpOnly | query · boolean | Adds HttpOnly. Default false. Default: false. |
secure | query · boolean | Adds Secure. Default false. Default: false. |
sameSite | query · string | lax, strict, none or unspecified (default, attribute omitted). |
maxAge | query · integer (int32) | Lifetime in seconds, clamped to 0-31536000. Omit for a session cookie; 0 expires it immediately. |
path | query · string | Cookie path. Must start with /, at most 128 characters, no ;. Default /. Default: "/". |
Responses
- 200
- The cookie and its attributes.
- 400
- Invalid name, value, path or sameSite.
Example
Request
curl -X GET "https://api.testingapis.com/api/cookies/set/theme/dark" \
-H "X-TestingApis-Key: YOUR_API_KEY"Response200 OK
Set-Cookie: theme=dark; path=/
{
"message": "Cookie 'theme' set",
"cookie": {
"name": "theme",
"value": "dark",
"path": "/",
"httpOnly": false,
"secure": false,
"sameSite": "unspecified",
"maxAge": null
},
"setCookieHeader": "theme=dark; path=/",
"warning": null
}Sign in to see the details
The parameters, request and response examples and the live Try it panel for this endpoint are for signed-in members. Accounts are free and take a few seconds to create.