Spring Boot Questions-2(REST)
08 May 2024 19:58
Ques: 31. Have you worked on Restful webservices ? If yes What all HTTP methods have you used in your project ?
• POST CREATE
• PUT UPDATE
• GET RETRIVE
• PATCH PARTIAL UPDATE
• DELETE REMOVE
Ques: 32. How can you specify the HTTP method type for your REST endpoint?
Ques: [Link] you design a rest endpoint, Assume that you have a product database, and your task is to create an API to filter a list of products by
productType.
Ques: [Link] endpoints in a way that takes "productType" as input. If the user provides this input, the endpoint should filter products based on the
specified condition. If "productType" is not provided, the endpoint should return all the products.
Ans:- PART 4
Ques: 35 What is the difference between @PathVariable and @RequestParam?
Ans:- @Path variable mandatory or else will throw 404. @RequestParam optional.
Ques: 36 How can we deserialize a JSON request payload into an object within a Spring MVC controller?
Ans:- @RequestBody
Ques: 37 Can we perform update operation in POST http method if yes then why do we need PUT mapping or put http method?
Ans: Yes , but it would violate the REST principles.
Ques: 36 Can we pass Request Body in GET HTTP method?
Ans: Technically Yes but not recommended.
Ques: 37 What all status code you have observed in your application?
Ques: 37 How can you customize the status code for your endpoint?
INTERVIEW Page 1
Ques: 37 How can you customize the status code for your endpoint?
Ans:-
Ques: 37 How can you enable cross origin?
Ans:-
2nd Way - Java based config
Ques: 37 How can you upload a file in spring?
Ques: 37 How do you maintain versioning for your REST API?
Ques: 38 How will you document your REST API?
Ques: 39 How can you hide certain REST endpoints to prevent them from being exposed externally?
INTERVIEW Page 2
Ques: 39 How can you hide certain REST endpoints to prevent them from being exposed externally?
Ques: 40 How will you consume restful API?
Using Rest -
Using Feign
Ques: 40 How will you handle exceptions in your project?
Ans:
INTERVIEW Page 3
Ques 41 How can you avoid defining handlers for multiple exceptions, or what is the best practise for handling exceptions?
Ans:- 1. Create a custom Exception.
2. Keep your code under try Catch.
3. For any Exception , suppress it with your Custom exception. Handle it under Exception Handler.
4. No need to create Exception Handler for every exception.
5.
Ques 42: How will you validate or sanitize your input payload?
Ans:- 1. Define Dependency <spring boot starter validation>.
[Link] to the particular class and use various annotations Ex:-Product class.
[Link] @Valid annotation in Controller to validate.
[Link] a custom exception for specific Error messages.
INTERVIEW Page 4
[Link] a custom exception for specific Error messages.
Ques 43. How can you define custom bean validation?
Ans:-Part 5
Ques 44:- use case: lets say you find a bug in production environment and now you want to debug the scenario, how can you do that from
your local?
Ans:- @Profiles. Change active environment profile in application properties.
Ques:45- How can you enable a specific environment without using profiles? OR what is the alternative to profiles to achieving same use
case?
Ans:- @Conditional. Available from spring boot.
1. There are multiple conditional annotations for different scenarios.
2. Use @ConditionalOnProperty.
INTERVIEW Page 5
2. Use @ConditionalOnProperty.
Ques 46:-What is AOP?
Ques 41. JWT tokens?
Ans: 41 [Link]
Ques 42. OAuth 2.0 ?
Ans: 42 OAuth2 Spring Boot - Scaler Topics
INTERVIEW Page 6