* JavaScript

  ```js
  export default {
    async fetch(request) {
      async function MethodNotAllowed(request) {
        return new Response(`Method ${request.method} not allowed.`, {
          status: 405,
          headers: {
            Allow: "GET",
          },
        });
      }
      // Only GET requests work with this proxy.
      if (request.method !== "GET") return MethodNotAllowed(request);
      return fetch(`https://example.com`);
    },
  };
  ```

  [Run Worker in Playground](https://workers.cloudflare.com/playground#LYVwNgLglgDghgJwgegGYHsHALQBM4RwDcABAEbogB2+CAngLzbPYZb6HbW5QDGU2AAwA2AIwBWAEwAOQZMkB2JQC4WLNsA5wuNPgJESZcxUoCwAKADC6KhACmt7ABEoAZxjpXUaDeUkNeATEJFRwwHYMAERQNHYAHgB0AFaukaSoUGAOYRHRsYkpkRbWtg4Q2AAqdDB2fnAwMGB8BFA2yElwAG5wrrwIsBAA1MDouOB2FhbxHkgkuHaocOAQJADe5iQkPXRUvP52ELwAFgAUCHYAjiB2rhAAlGsbm1uuO3uo1Lw+VCQAsgdHUYAOXQEAAgmAwOgAO52XBnS7XW4PdbPZ7nCAgBA-Kh2aEkABKNw8VFcdhOAAN-hBAbgSAASVbnK43CAJcI00YAXxCoK2kJhcISFIANI80WjbgQQK4-AAWQTiEVPCUkI52ODzBCy8Wq54QqHQvyRADiAFEKpFlXqSFzrRKuXciCrbS7kMgSAB5KhgOgkc0VEjMpEQVwkaGYADW4e8RxINLcJBgCHQcToCRdUFQJARLNu7IBoxIAEIGAwSKaLZEHhisT9qbSQeCBbD4cHWU6XbXsftDqcKUcIBAYLL3fEwo07AleOhgBTO5s7eYuUQLGpmBotDoePwhGIpLJ5EoFMUbPZHC53J5vK0qH4AlpSKFwlEOZqgml-Jlsi-ImQoWQRRWGeZSVNUtRbA0TS8C0bQpDYkzmKskTAHAMQAPojGMWSRMoeTzAUqRcmu66bkE256HuhiHiYCjMEAA)

* TypeScript

  ```ts
  export default {
    async fetch(request): Promise<Response> {
      async function MethodNotAllowed(request) {
        return new Response(`Method ${request.method} not allowed.`, {
          status: 405,
          headers: {
            Allow: "GET",
          },
        });
      }
      // Only GET requests work with this proxy.
      if (request.method !== "GET") return MethodNotAllowed(request);
      return fetch(`https://example.com`);
    },
  } satisfies ExportedHandler;
  ```

* Python

  ```py
  from workers import Response, fetch


  def on_fetch(request):
      def method_not_allowed(request):
          msg = f'Method {request.method} not allowed.'
          headers = {"Allow": "GET"}
          return Response(msg, headers=headers, status=405)


      # Only GET requests work with this proxy.
      if request.method != "GET":
          return method_not_allowed(request)


      return fetch("https://example.com")
  ```
