Suppose I have a REST API and I can fetch the list of my friends and the favorite songs of each friend in my list. Now I want to fetch all favorite songs of all my friends. The problem with REST API is that I can’t do that just using only one request. I must make a request to get my friends and then do a request for each friend.
I have read about the framework that I don’t remember the name that permit to do that in only one request.
Do you know an idea about the technology that can do that?
5
Right now I am using Spring in order to handle the REST calls. It works with Java-Annotations and can also convert the objects you are returning to JSON on the fly.
I think it is pretty convenient to use so far and it works well in combination with Hibernate (ORM).
For example:
@RestController
public class GreetingController {
private static final String template = "Hello, %s!";
private final AtomicLong counter = new AtomicLong();
@RequestMapping("/greeting")
public Greeting greeting(@RequestParam(value="name", defaultValue="World") String name) {
return new Greeting(counter.incrementAndGet(),
String.format(template, name));
}
}
Will give you the output:
{
"id": 1,
"content": "Hello, World!"
}
But just take a look at this tutorial.
To avoid multiple calls you could just pass all necessary parameters in one call and simply return a list of friends and their songs. Processing large data is another thing Spring can do for you.
EDIT:
Reading over your question again I am not sure if what you wanted is a technology for REST calls or if you just need a powerful ORM tool. In that case, like mentioned before, Hibernate is a very powerful tool. It has its learning curve but I think it’s worth it. If you go for Hibernate definitely take a look at this!