REST and SOAP API Development Essentials
API Documentation and Swagger
How is API documentation generated using Swagger and OpenAPI?
✅ By annotating the code with Swagger annotations.
What is one of the main advantages of using Swagger for API documentation?
✅ It automatically generates interactive documentation.
How does implementing clear annotations in code enhance code readability?
✅ By providing descriptive comments and clarifications.
HTTP Status Codes and Methods
Which HTTP status code is typically used to indicate that a resource has been successfully created?
✅ 201
Which HTTP method is used to retrieve data from a server in a RESTful service?
✅ GET
Which of the following HTTP status codes indicates that a client request was successful but no content is returned?
✅ 204
Spring Boot and JAX-RS Annotations
- @RequestBody: Used in Spring Boot to map a JSON request body to a method parameter.
- @ApplicationPath: Defines the root application path for all REST endpoints in JAX-RS.
- @Produces: Specifies the MIME type(s) that a resource can produce.
- @QueryParam: Allows you to extract query parameters from a request URL.
- @Path: Defines the base URI for a resource class in JAX-RS.
- @POST: Used to handle HTTP POST requests.
- @RolesAllowed: Restricts access to users with specific roles.
What is the primary difference between a path variable and a request parameter in Spring Boot?
✅ Path variables are part of the URL, while request parameters are included in the query string.
API Versioning and Best Practices
- Best Practice 1: Using URI paths to indicate versions.
- Best Practice 2: Using semantic versioning.
- Statelessness: Ensures the client does not need to maintain session state, as all necessary information is included in each request.
SOAP Web Services
What is the primary format used by SOAP messages?
✅ XML
Are SOAP web services limited to HTTP?
✅ False
What is the role of WSDL in SOAP web services?
✅ It describes the service interface and operations.
Is a SOAP Fault an XML-formatted error message?
✅ True
Code Examples
@GET
@Path("/cars")
public String getCars(@MatrixParam("color") String color) {
return color;
}✅ True
JAX-RS Annotations Example
@Path("/credit-cards-api")
public class CreditCardResource {
@POST
@Path("/validate")
@Consumes({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
@Produces(MediaType.APPLICATION_JSON)
public boolean isValid(CreditCard cc) {
return true;
}
}cURL Command
curl -X POST http://localhost:8080/credit-cards-api/validate \
-H "Content-Type: application/json" \
-d '{"number":"1234567890123456","expiry":"12/26","cvv":"123"}'
