Skip to content

Latest commit

 

History

History

transform

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 

Netlify examples

Transform responses with Netlify Edge Functions

You can use Edge Functions to transform the content of an HTTP response. In this example, we transform the response of a request to /hello with JavaScript's toUpperCase() function, using the query parameter ?method=transform.

Code example

Edge Functions are files held in the netlify/edge-functions directory.

import { Context } from "@netlify/edge-functions";

export default async (request: Request, context: Context) => {
  const url = new URL(request.url);

  // Look for the query parameter, and return if we don't find it
  if (url.searchParams.get("method") !== "transform") {
    return;
  }

  console.log(`Transforming the response from this ${url}`);

  const response = await context.next();

  const text = await response.text();
  return new Response(text.toUpperCase(), response);
};

View this example on the web

Deploy to Netlify

You can deploy this and all the other examples in this repo as a site of your own to explore and experiment with, by clicking this button.

Deploy to Netlify