spring-boot-custom-endpoints-using-regex
What do you do when REST conventions are seemingly impossible to follow?
Let's say we have a user management system that we designed using the REST API guidelines.
The URL on which we access a user would be: /users/{userId}
Say your business logic is based on the userId.
You don't want change the URL as you would break the REST API conventions, so the client requests should still be sent to /users/{userId}.
This is where Spring comes to rescue. 🚒
RequestMapping and all its implementations GetMapping, PostMapping, etc. support Regular Expressions so you have even more precision when defining your Controllers.
You can find more details on the official Spring MVC Documentation website.
For our case we can write something like this:
Let's test it with some requests in Postman. 🚀