user1409637
user1409637

Reputation:

Creating a Client using Spring MVC for a RESTful API

I'm new to Spring framework and REST concepts. I've been working on a project to grasp these concepts efficiently. I'm building a quiz tool where a user can login using his credentials and take a quiz. I've created a RESTful API for same using JAX-RS. And now I want to create a Client which will work over this API, using Spring MVC. Is that possible and how to start with that ?? I mean, How do I use Spring MVC to create a Client for my RESTful API ??

some of my resources are -

GET   /scorecard      
GET   /scorecard/{quizId}
GET   /scorecard/{userId}
GET   /quiz/{questionId}
POST  /quiz/{questionId}
and so on..

I'm really confused about the design aspects about a client using Spring MVC. Do I include the logic of evaluating quiz,calculating & storing scores in the API or in the spring MVC client ??

Thanx in advance.

Upvotes: 0

Views: 1980

Answers (2)

apurvc
apurvc

Reputation: 750

I would suggest checkout spring mvc showcase project from Github and experimenting with source code.

spring-mvc-showcase

You can easily use your browser as client for quite a few REST calls.

Design for application depends on requirements. e.g. Keeping the score at client will keep you free from session management otherwise you will need to handle at server.

Upvotes: 0

David Robles
David Robles

Reputation: 9607

Here is an example of the first two endpoints implemented with Spring MVC:

@Controller
@RequestMapping(value = "/scorecard")
public class ScorecardController {

    @Autowired
    private ScorecardService scorecardService;

    // GET   /scorecard
    @RequestMapping(method = RequestMethod.GET)
    public List<Scorecard> getScorecards()
    {
        List<Scorecard> scorecards = scorecardService.getScorecards();
        return scorecards;
    }

    // GET   /scorecard/{quizId}
    @RequestMapping(value = "/{quizId}", method = RequestMethod.GET)
    public List<Scorecard> getScorecardsByQuizId(@PathVariable long quizId)
    {
        List<Scorecard> scorecards = scorecardService.getScorecardsByQuizId(quizId);
        return scorecards;
    }
}

Upvotes: 1

Related Questions