I'm creating a Rest api in Java with Spring and have urls such as
GET http://host:port/products/{resource}
The id's of resources are typically like version numbers such as 3.2
or a more elaborate example is x-light.5p
.
Unfortunately, Spring seems to cut off the last part, thinking it is an extension (like .html
or .png
) so what actually enters my controller is not 3.2
but 3
and not x-light.5p
but x-light
. I experimented a bit and noticed that ending the request with an additional slash does work: GET http://host:port/products/x-light.5p/
does enter the controller in full.
For obvious reasons, changing our id's is a no go. Why is Spring behaving this way and can I change it? What would happen if I change my controller mapping from /products/{resource}
to /products/{resource}/
? Is this a way to enforce those who call the api to append the last slash? I thought the last slash was mostly redundant.