# Snippets > Links below point directly to Markdown versions of each page. Any page can also be retrieved as Markdown by sending an `Accept: text/markdown` header to the page's URL without the `index.md` suffix (for example, `curl -H "Accept: text/markdown" https://developers.cloudflare.com/rules/snippets/`). > > For other Cloudflare products, see the [Cloudflare documentation directory](https://developers.cloudflare.com/llms.txt). ## Overview - [Cloudflare Snippets](https://developers.cloudflare.com/rules/snippets/index.md): Run lightweight JavaScript at the edge to modify requests and responses. ## How Snippets work - [How Snippets work](https://developers.cloudflare.com/rules/snippets/how-it-works/index.md): How Snippets execute JavaScript at the edge for matching requests. ## Create a snippet in the dashboard - [Create a snippet in the dashboard](https://developers.cloudflare.com/rules/snippets/create-dashboard/index.md): Create Snippets in the Cloudflare dashboard. ## Configure Snippets via API - [Configure Snippets via API](https://developers.cloudflare.com/rules/snippets/create-api/index.md): Create Snippets using the Cloudflare API. ## Configure Snippets using Terraform - [Configure Snippets using Terraform](https://developers.cloudflare.com/rules/snippets/create-terraform/index.md): Create Snippets using the Terraform Cloudflare provider. ## Snippets examples - [Snippets examples](https://developers.cloudflare.com/rules/snippets/examples/index.md): Example Snippets for headers, redirects, caching, and more. - [A/B testing with same-URL direct access](https://developers.cloudflare.com/rules/snippets/examples/ab-testing-same-url/index.md): Set up an A/B test by controlling what response is served based on cookies. - [Append dates to cookies to use with A/B testing](https://developers.cloudflare.com/rules/snippets/examples/append-dates-to-cookies/index.md): Dynamically set a cookie expiration and test group. - [Auth with headers](https://developers.cloudflare.com/rules/snippets/examples/auth-with-headers/index.md): Allow or deny a request based on a known pre-shared key in a header. This is not meant to replace the [WebCrypto API](/workers/runtime-apis/web-crypto/). - [Send Bot Management information to origin](https://developers.cloudflare.com/rules/snippets/examples/bot-data-to-origin/index.md): Send [Bots](/bots/) information to your origin. Refer to [Bot Management variables](/bots/reference/bot-management-variables/) for a full list of available fields. - [Send suspect bots to a honeypot](https://developers.cloudflare.com/rules/snippets/examples/bots-to-honeypot/index.md): Use the [bot score field](/workers/runtime-apis/request/#incomingrequestcfproperties) to send bots to a honeypot. - [Bulk redirect based on a map object](https://developers.cloudflare.com/rules/snippets/examples/bulk-redirect-map/index.md): Redirect requests to certain URLs based on a mapped object to the request's URL. - [Country code redirect](https://developers.cloudflare.com/rules/snippets/examples/country-code-redirect/index.md): Redirect a response based on the country code in the header of a visitor. - [Custom cache](https://developers.cloudflare.com/rules/snippets/examples/custom-cache/index.md): Store, retrieve, and remove assets from cache programmatically. Use this template to optimize performance and implement custom caching strategies. - [Debugging logs](https://developers.cloudflare.com/rules/snippets/examples/debugging-logs/index.md): Send debugging information in an errored response to a logging service. - [Define CORS headers](https://developers.cloudflare.com/rules/snippets/examples/define-cors-headers/index.md): Adjust [Cross-Origin Resource Sharing (CORS)](https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS) headers and handle preflight requests. - [Follow redirects from the origin](https://developers.cloudflare.com/rules/snippets/examples/follow-redirects/index.md): Modify the fetch request to follow redirects from the origin, ensuring the client receives the final response. - [Add HEX timestamp to a request header](https://developers.cloudflare.com/rules/snippets/examples/hex-timestamp/index.md): Add a custom header to requests sent to the origin server with the current timestamp in hexadecimal format for debugging, tracking, or custom routing purposes. - [Validate JSON web tokens (JWT)](https://developers.cloudflare.com/rules/snippets/examples/jwt-validation/index.md): Extract a JWT from the Authorization header, verify its HMAC-SHA256 signature using the WebCrypto API, and validate its claims. - [Maintenance page](https://developers.cloudflare.com/rules/snippets/examples/maintenance/index.md): Serve a custom maintenance page instead of fetching content from the origin server or cache. Ideal for downtime notifications, planned maintenance, or emergency messages. - [Override a Set-Cookie header with a certain value](https://developers.cloudflare.com/rules/snippets/examples/override-set-cookies-value/index.md): Get a specific `Set-Cookie` header and update it with a certain value. - [Redirect 403 Forbidden to a different page](https://developers.cloudflare.com/rules/snippets/examples/redirect-forbidden-status/index.md): If origin responded with `403 Forbidden` error code, redirect to different page. - [Redirect from one domain to another](https://developers.cloudflare.com/rules/snippets/examples/redirect-replaced-domain/index.md): Redirect all requests from one domain to another domain. - [Remove fields from API response](https://developers.cloudflare.com/rules/snippets/examples/remove-fields-api-response/index.md): If origin responds with `JSON`, parse the response and delete fields to return a modified response. - [Remove query strings before sending request to origin](https://developers.cloudflare.com/rules/snippets/examples/remove-query-strings/index.md): Remove certain query strings from a request before passing to the origin. - [Remove response headers](https://developers.cloudflare.com/rules/snippets/examples/remove-response-headers/index.md): Remove from response all headers that start with a certain name. - [Return information about the incoming request](https://developers.cloudflare.com/rules/snippets/examples/return-incoming-request-properties/index.md): Respond with information about the incoming request provided by Cloudflare’s global network. - [Rewrite links on HTML pages](https://developers.cloudflare.com/rules/snippets/examples/rewrite-site-links/index.md): Dynamically rewrite links in HTML responses. This is useful for site migrations and branding updates. - [Change origin and modify paths](https://developers.cloudflare.com/rules/snippets/examples/route-and-rewrite/index.md): Route requests to a different origin, prepend a directory to the URL path, and remove specific segments. - [Set security headers](https://developers.cloudflare.com/rules/snippets/examples/security-headers/index.md): Set common security headers such as X-XSS-Protection, X-Frame-Options, and X-Content-Type-Options. - [Send timestamp to origin as a custom header](https://developers.cloudflare.com/rules/snippets/examples/send-timestamp-to-origin/index.md): Convert timestamp to hexadecimal format and send it as a custom header to the origin. - [Route to a different origin based on origin response](https://developers.cloudflare.com/rules/snippets/examples/serve-different-origin/index.md): If response to the original request is not `200 OK` or a redirect, send to another origin. - [Sign requests](https://developers.cloudflare.com/rules/snippets/examples/signing-requests/index.md): Verify a signed request using the HMAC and SHA-256 algorithms or return a 403. - [Slow down suspicious requests](https://developers.cloudflare.com/rules/snippets/examples/slow-suspicious-requests/index.md): Define a delay to be used when incoming requests match a rule you consider suspicious based on the bot score. ## Troubleshoot Snippets - [Troubleshoot Snippets](https://developers.cloudflare.com/rules/snippets/errors/index.md): Common Snippet errors and how to resolve them. ## When to use Snippets vs Workers - [When to use Snippets vs Workers](https://developers.cloudflare.com/rules/snippets/when-to-use/index.md): This guide helps you determine when to use Snippets or Workers on Cloudflare's global network.