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 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.
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.
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 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.
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.
from and to of the mappings so that the result is a valid, percent-encoded URI.rewriter with an expression in the target url. Either build the path in the expression itself, or use a static target URL.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.
Configuration reference:
Tutorials with runnable examples:
Still stuck? See the troubleshooting guide or ask on GitHub Issues. For commercial support, contact info@predic8.de.