How to support both json and html response with Spring Boot

767 views Asked by At

I want to send data to both mobile (using json) and web (using html) and I am using Spring boot. I want to attain similar architecture and functionality as used by facebook(graph.facebook.com and facebook.com) and twitter(api.twitter.com and twitter.com) . Also I am using Angular.js as a web framework.

1

There are 1 answers

4
sodik On BEST ANSWER

Nothing prevents you to make two different implementations (json, html) and serve it from same URL. Just use proper Consumable Media Types or Producible Media Types eg:

@Controller
@RequestMapping(value = "/pets/{petId}", method = RequestMethod.GET, produces="application/json")
@ResponseBody
public Pet getPet(@PathVariable String petId, Model model) {
    // implementation omitted
}