Here is another update on my gitconfig:
Wednesday, March 8, 2017
Saturday, March 4, 2017
REST Endpoint returning 404 without Exceptions
At some point in your REST endpoint design, you will need to return a non 200 response. Now, most implementations show how to implement this using exceptions. While this may seem like a nice approach (from a programming language point of view), exceptions can add overhead to the running JVM. This translates to ineffective use of resources of the JVM for supporting non 200 responses.
Here is a gist where you don't use exceptions to return non 200 responses:
A few things to note from this snippet:
Here is a gist where you don't use exceptions to return non 200 responses:
A few things to note from this snippet:
- This is a Spring Boot implementation (Boot makes things so much simple)
- The HttpServletResponse is injected by Boot (Spring MVC), no need of additional setup.
- Notice that the body return is null already, so the non 200 response makes more sense.
Subscribe to:
Posts (Atom)