Introduction to REST in Java with JAX-RS
Hmmm only if Java was called Pava, it would be RIP (REST in Pava). Haha.
Here's what we want to do to achieve REST in Java (very similar to Servlet, actually!)
- make our Resources available to HTTP requests
basically, we want to specify what happens with GET (or any HTTP methods) request to certain url endpoint like localhost:8080/services/hello.
Make Resource
Resources are equivalent to Servlet, with some differences.
The difference here is that unlike in our servlet example, web.xml doesn't need to do any mapping. In fact, it's empty! Resource above defines what happens with GET request to (something)/greetings/hello. The reason why I had '(something)' written is because there's a parent class that maps Resource to top level url.
Map resource to url
This is all you need! So we defined what happens with GET request to /services/greetings/hello
In fact:
http://localhost:8080/example_05_jax_rs_war_exploded/services/greetings/hello
produces
That's it!