Skip to content

Files

Latest commit

c706310 · Nov 1, 2024

History

History

proxy-requests

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
Nov 1, 2024
Nov 1, 2024

Netlify examples

Proxy requests to another source

You can use fetch() to make requests to other sources via an Edge Function.

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 joke = await fetch("https://icanhazdadjoke.com/", {
    headers: {
      Accept: "application/json",
    },
  });
  const jsonData = await joke.json();
  return Response.json(jsonData);
};

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