You can use fetch() to make requests to other sources via an Edge Function.
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);
};
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.