0

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.

2 Answers 2

1

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;
    }
}
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks David. Also,can you tell me how to connect my client to the API ?? And should I include my business logic (evaluating quiz,calculating scores,authentication etc.) on the client side ?? (since my service is RESTful and assuming my client runs on web on different server.)
0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.