7

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?

  • software recommendations are explicitly off-topic per help center (it's the same here as at Stack Overflow). See meta.programmers.stackexchange.com/questions/6483/… – gnat May 7 '15 at 9:03
  • Why not make a route /user/me/friends/songs and then return the list of friends with each of their songs. or return just a list of their songs. – Michael Malura May 7 '15 at 9:13
  • 1
    @gnat I'm not searching a framework but the technology. I changed my question. – Hunsu May 7 '15 at 9:21
  • @MichaelMalura yes I can do that but there's cases when you can't find a solution like that. For example if there's many relations – Hunsu May 7 '15 at 9:22
  • It's all a breeze when you know what you're after. Basically an ORM over REST. – Joe May 7 '15 at 16:27
0

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!

Not the answer you're looking for? Browse other questions tagged or ask your own question.