Deno LandDeno

Deploy Docs

Fetch API

The Fetch API allows you to make outbound HTTP requests in Deno Deploy. It is a web standard and has the following interfaces:

This page shows usage for the fetch() method. You can click above on the other interfaces to learn more about them.

fetch()

The fetch() method initiates a network request to the provided resource and returns a promise that resolves after the response is available.

function fetch(
  resource: Request | string,
  init?: RequestInit,
): Promise<Response>;

Parameters

name type optional description
resource Request
USVString
false The resource can either be a request object or a URL string.
init RequestInit true The init object lets you apply optional parameters to the request.

The return type of fetch() is a promise that resolves to a Response.

Examples

The Deno Deploy script below makes a fetch() request to GitHub API on a new request and returns the response from GitHub back to the client who made the request to the Deno Deploy script.

addEventListener("fetch", (event) => {
  event.respondWith(
    // We're using the GitHub API endpoint as the request resource.
    fetch("https://api.github.com/users/denoland", {
      // The init object here has an headers object containing a
      // header that indicates what type of response we accept.
      // We're not specifying the method field since by default
      // fetch makes a GET request.
      headers: {
        accept: "application/json",
      },
    }),
  );
});

Also checkout Make an outbound request post for more examples.


Please file an issue in our feedback repository if you find any problem in Deploy service or documentation.