Open Source API Gateway

400 Bad Request: Path Does Not Follow the URI Specification

Membrane API Gateway returns 400 Bad Request with the title The path does not follow the URI specification. Confirm the validity of the provided URL. when the rewriter plugin cannot parse the destination URL, or the URL a mapping rewrote the path to. The request does not reach the backend.

The Error Response

The response contains the status 400 Bad Request, the title The path does not follow the URI specification. Confirm the validity of the provided URL., a detail with the parser message that names the invalid character and its position, the destination, the problem type https://membrane-api.io/problems/user/path and a link to this page. The type user/path means that the path of the request or the configuration caused the problem.

What the rewriter Plugin Does

The rewriter changes the path of a request using regular expressions. Each mapping has a from expression and a to replacement. A to that contains :// redirects the client to an absolute URL. See How to Rewrite a Path.

api:
port: 2000
flow:
- rewriter:
- from: ^/store/(.*)
to: /shop/v2/$1
target:
url: https://api.predic8.de
api:
  port: 2000
  flow:
    - rewriter:
        - from: ^/store/(.*)
          to: /shop/v2/$1
  target:
    url: https://api.predic8.de

After rewriting, the plugin parses the result as a URI. If that fails, it answers with this error.

Common Causes

An Expression in the Target URL

If the url of the API's target contains an expression such as ${...}, the expression is evaluated only after the rewriter has run. The rewriter then likely sees the raw { and } characters, which are not allowed in a URI.

A Mapping Produces an Invalid Absolute URL

A to with :// produces a URL that is not a valid URI, for example because the regular expression captures spaces or other illegal characters from the request and inserts them into the URL.

Illegal Characters in the Destination

The destination contains characters that are not allowed in a URI, or a broken percent-encoding. They can come from the target URL or from the request path.

How to Fix It

  1. Read the detail. It names the invalid character and its position in the destination.
  2. As an operator, check the from and to of the mappings so that the result is a valid, percent-encoded URI.
  3. Do not combine the rewriter with an expression in the target url. Either build the path in the expression itself, or use a static target URL.
  4. As a client, percent-encode special characters in the request path and query.

Details in Production Mode

Unlike most errors, this response is not shortened in production mode. It contains the detail, the destination and the link to this page even with production: true. The destination can reveal the URL of your backend, so make sure your mappings and target URLs always produce valid URIs.

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.