Rest_API_Interview_Questions_with_Answers_1743171492
Rest_API_Interview_Questions_with_Answers_1743171492
com/in/sumathi1989 1
Rest API
1. Rest API?
A REST API provides endpoints that allow clients to communicate with a server over the
internet. Each endpoint represents a specific resource or action, such as retrieving data,
creating new data, updating existing data, or deleting data. Clients send requests to
these endpoints using HTTP methods like GET, POST, PUT, PATCH, and DELETE, and the
server responds with the requested data or performs the requested action.
Stateless: Each request from a client must contain all the necessary information, as
the server does not store session data.
Client-Server Architecture: The client and server are independent.
Cacheable: Responses can be cached to improve performance.
Layered System: APIs can have multiple layers for security, load balancing, etc.
Uniform Interface: Uses standard HTTP methods and URIs for interaction.
An idempotent operation means that making multiple identical requests will not
change the server state beyond the first request.
Idempotent methods: GET, PUT, DELETE, HEAD, OPTIONS
Non-idempotent methods: POST, PATCH
Example: Calling DELETE /users/123 multiple times should delete the user once and
return the same response.
200 OK – Success
201 Created – Resource successfully created
204 No Content – Success but no response body
400 Bad Request – Client error (invalid request)
401 Unauthorized – Authentication required
403 Forbidden – Client does not have access
404 Not Found – Resource does not exist
500 Internal Server Error – Generic server error
9. What are the key annotations used to create a REST API in Spring Boot?
Spring Boot provides the following annotations for building REST APIs:
10. How does Spring Boot support the creation of RESTful APIs?
Spring Boot provides excellent support for creating RESTful APIs using Spring MVC and
embedded HTTP servers like Tomcat, Jetty, or Undertow. Developers can define
RESTful endpoints using `@RestController` and `@RequestMapping` annotations,
handle request and response payloads with ease, and leverage features like content
negotiation, validation, and error handling.
The above returns a JSON response. If we used @Controller, it would return a view name instead.
www.linkedin.com/in/sumathi1989 4
An API Gateway acts as an entry point for all client requests, handling authentication,
load balancing, and routing.
Spring Cloud Gateway is the most used gateway in Spring Boot microservices.
Simplicity: RESTful services are based on a simple architectural style that uses standard
HTTP methods (GET, POST, PUT, DELETE) and resource-based URLs. This simplicity
makes it easy to understand and use RESTful APIs.
Scalability: RESTful services are stateless, meaning each request from a client contains
all the information needed by the server to fulfil the request. This statelessness makes
it easier to scale RESTful services horizontally by adding more servers to handle
increased load.
Flexibility: RESTful services support multiple data formats, including JSON, XML, and
plain text, making them suitable for a wide range of clients and applications.
Caching: RESTful services leverage the built-in caching mechanisms of HTTP to improve
performance and reduce server load. Clients can cache responses from the server to
avoid unnecessary round trips for the same data.
Statelessness: RESTful services are stateless, meaning each request from a client
contains all the information needed by the server to fulfil the request. This simplifies
server-side logic and improves reliability.
Overall, RESTful services provide a lightweight, scalable, and interoperable way to build
distributed systems and expose APIs for communication between different software
components. They have become the preferred choice for building web services and
APIs due to their simplicity, flexibility, and compatibility with modern web development
practices.
www.linkedin.com/in/sumathi1989 7
HATEOAS (Hypermedia as the Engine of Application State) is a REST principle that provides
links to related resources in the API response, allowing clients to navigate dynamically.
--------------------------------------------------END----------------------------------------------------------