Cookie parsing
Given the cookie name, get the value of a cookie. You can also use cookies for A/B testing.
If you want to get started quickly, click on the button below.
This creates a repository in your GitHub account and deploys the application to Cloudflare Workers.
import { parse } from "cookie";export default {  async fetch(request) {    // The name of the cookie    const COOKIE_NAME = "__uid";    const cookie = parse(request.headers.get("Cookie") || "");    if (cookie[COOKIE_NAME] != null) {      // Respond with the cookie value      return new Response(cookie[COOKIE_NAME]);    }    return new Response("No cookie with name: " + COOKIE_NAME);  },};import { parse } from "cookie";export default {  async fetch(request): Promise<Response> {    // The name of the cookie    const COOKIE_NAME = "__uid";    const cookie = parse(request.headers.get("Cookie") || "");    if (cookie[COOKIE_NAME] != null) {      // Respond with the cookie value      return new Response(cookie[COOKIE_NAME]);    }    return new Response("No cookie with name: " + COOKIE_NAME);  },} satisfies ExportedHandler;from http.cookies import SimpleCookiefrom workers import Response
async def on_fetch(request):    # Name of the cookie    cookie_name = "__uid"
    cookies = SimpleCookie(request.headers["Cookie"] or "")
    if cookie_name in cookies:        # Respond with cookie value        return Response(cookies[cookie_name].value)
    return Response("No cookie with name: " + cookie_name)import { Hono } from 'hono';import { getCookie } from 'hono/cookie';
const app = new Hono();
app.get('*', (c) => {  // The name of the cookie  const COOKIE_NAME = "__uid";
  // Get the specific cookie value using Hono's cookie helper  const cookieValue = getCookie(c, COOKIE_NAME);
  if (cookieValue) {    // Respond with the cookie value    return c.text(cookieValue);  }
  return c.text("No cookie with name: " + COOKIE_NAME);});
export default app;Was this helpful?
- Resources
 - API
 - New to Cloudflare?
 - Products
 - Sponsorships
 - Open Source
 
- Support
 - Help Center
 - System Status
 - Compliance
 - GDPR
 
- Company
 - cloudflare.com
 - Our team
 - Careers
 
- 2025 Cloudflare, Inc.
 - Privacy Policy
 - Terms of Use
 - Report Security Issues
 - Trademark