Open Source API Gateway

404 Not Found: Invalid Path or Method

Membrane API Gateway returns 404 Not Found with the title Invalid path or method when a request arrives on one of its ports, but no API matches the request. Membrane does not know where to route the request and rejects it.

The Error Response

The response contains the status 404 Not Found, the title Invalid path or method, the message The requested path or HTTP method is not supported., the problem type https://membrane-api.io/problems/user and a link to this page. The type user means that the request or the configuration caused the problem, not an internal failure of the gateway.

How Membrane Routes Requests

For every incoming request, Membrane looks for an api whose criteria all match the request:

CriterionConfigurationDefault
PortportRequired
Host headerhostAny host
HTTP methodmethodAny method
Pathpath.uri, or the base paths of an openapi documentAny path

If no API on the port matches, Membrane answers with this error. The APIs are checked in the order in which they appear in the configuration, and the first match wins.

Common Causes

The Path Does Not Match

A path is matched as a prefix. The following API accepts /shop/products and /shop/orders/7, but a request to /products or /Shop fails with Invalid path or method:

api:
port: 2000
path:
uri: /shop
target:
url: https://api.predic8.de
api:
  port: 2000
  path:
    uri: /shop
  target:
    url: https://api.predic8.de

Check the request URL for typos, missing prefixes and case. If isRegExp: true is set, the uri is treated as a regular expression, so check that the expression matches the path.

The Method Is Restricted

An API with a method accepts only that HTTP method. A POST to this API is rejected:

api:
port: 2000
method: GET
path:
uri: /shop
target:
url: https://api.predic8.de
api:
  port: 2000
  method: GET
  path:
    uri: /shop
  target:
    url: https://api.predic8.de

Remove method to accept all methods, or add another API for the missing method.

The Host Does Not Match

With host set, the Host header of the request must match. Calling the gateway by IP address or through localhost instead of the configured host name fails.

The OpenAPI Base Path Does Not Match

An API deployed from an OpenAPI document is routed using the paths of the servers URLs in that document. If the servers URL is https://api.example.com/shop/v2, requests must start with /shop/v2.

The Request Hits the Wrong Port

If there is no API for the path on the port you are calling, the request cannot be routed, even if another port has a matching API. Check the port in the URL against the port of your APIs.

How to Fix It

  1. Note the port, Host header, method and path of the failing request.
  2. Compare them with the api definitions in your apis.yaml.
  3. Either correct the request, or change or add an API that matches it.

To accept all remaining requests on a port, place a catch-all API without path and method after the more specific ones:

api:
port: 2000
path:
uri: /shop
target:
url: https://api.predic8.de
---
api:
port: 2000
flow:
- return:
status: 404
api:
  port: 2000
  path:
    uri: /shop
  target:
    url: https://api.predic8.de
---
api:
  port: 2000
  flow:
    - return:
        status: 404

Hide Details in Production

By default, Membrane runs in development mode and adds details to error responses that help you find the problem. These details may reveal information about your setup. In production, turn them off:

configuration:
production: true
configuration:
  production: true

Add the configuration document to your apis.yaml and separate it from the APIs with ---.

Related Documentation

Configuration reference:

Tutorials with runnable examples:

← All Membrane error messages

Still stuck? See the troubleshooting guide or ask on GitHub Issues. For commercial support, contact info@predic8.de.