-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Trailing Slashes in REST API endpoints Results in 405 #972
Comments
@salekinsirajus Would you say that this needs a documentation improvement -- e.g. "Don't do this: ..." or "Do it this way... " -- or do the docs currently claim that |
405 is the wrong status code in this case. We should review the current APIs and document the current behaviour (just in this issue would be a good start.) Then we can decide how to handle trailing slashes in a way that's consistent across all of the APIs. |
This is a well-known issue with HTTP REST frameworks. Normally a redirect is sent if there is no trailing slashes to the URL with slashes (and vice-versa). If enabled it should just work https://godoc.org/github.com/gorilla/mux#Router.StrictSlash BTW, some clients (such as curl?) do not follow redirects, POSTMAN does. |
I guess I can fix this one |
Stripping the trailing slash or redirecting trailing slash URIs on the V1 APIs should be fine |
okay, I will set Router.StrictSlash and see how it plays out |
Problem
When used the OPA REST API to upload data or policies, a slash at the endpoint causes the API to reject the request and results in a 405 (Method Not Allowed) response.
I am not sure if it is the case for every endpoint, but that might very well be the case.
How to Reproduce
Contents of
data.json
:(Optional) The above file can be validated with
./opa run data.json
to make sure it's formatted correctly.Now if we want to upload this data with the Data API, like this:
However, if we remove the trailing slash (
localhost:8181/v1/data
), the API works as it's intended:The text was updated successfully, but these errors were encountered: