Loading

Quipoin Menu

Learn • Practice • Grow

spring / REST API Introduction
interview

Q1. What is a REST API?
REST (Representational State Transfer) is an architectural style for designing networked applications. It relies on stateless, client-server communication, typically over HTTP. RESTful APIs use HTTP methods (GET, POST, PUT, DELETE) to perform CRUD operations on resources identified by URLs, and usually return JSON or XML.

Q2. What are the key principles of REST?
Key principles: Client-server separation, statelessness, cacheability, uniform interface (resources identified by URLs, manipulation through representations), layered system, and optionally code on demand. REST APIs should be stateless, meaning each request contains all necessary information.

Q3. How does Spring support REST API development?
Spring MVC provides annotations like @RestController, @RequestMapping, @ResponseBody for building RESTful services. Spring also offers support for content negotiation, HTTP message converters (Jackson for JSON), and exception handling via @ControllerAdvice.

Q4. What is @RestController?
@RestController is a convenience annotation that combines @Controller and @ResponseBody. It indicates that every handler method in the controller should have its return value written directly to the HTTP response body (as JSON/XML) rather than being resolved as a view name.

Q5. What is the difference between @Controller and @RestController?
@Controller is used in traditional MVC where methods return view names. @RestController is used for REST APIs where methods return domain objects directly, with automatic serialization. @RestController also implies @ResponseBody on all methods.