Rest Webservices/API Interview Questions and Answers

Questions: Write rest api which will return either XML or JSON based on the request type?
Answer:
1. Mark your method with produce type of the response you want to return

 @RequestMapping(value = "/employee", method = RequestMethod.GET,
   produces = { "application/json", "application/xml" })
 public ResponseBody<Employee> getEmployee() {

2. Next we overwrite configureContentNegotiation method in our configuration class. We set the In defaultContentType(MediaType.APPLICATION_JSON). default content type is set. It means that if we don't pass path expression then Spring will generate JSON as response. The configuration will be as follows depending on the content negotiation type
  • Using Path Extension

How do I handle an unknown number of RequestParams in Spring Boot REST?

1.  One way to do that would be receive a Map with the params, the problem is that all the params would have the same type, and you would have to cast to the proper type in your code:

@ResponseBody
public String updateFoos(@RequestParam Map<String,Object> allParams) {
    return "Parameters are " + allParams.entrySet();
}

2. we can use @RequestBody
@PostMapping("/test")
public MyClass getData(@RequestBody ParamClass params) { 

    return something;
}
How many parallel requests are allowed in Spring microservice?
How would you handle higher than allowed counts of parallel requests?
200 are supported by Spring microservices. we would need create multiple instances to allow more request.


api throttling vs rate limiting

https://blog.stoplight.io/best-practices-api-rate-limiting-vs-throttling


 https://www.javainuse.com/spring/spring-boot-content-negotiation

https://www.javainuse.com/devOps/docker/docker-war
SHARE

esant technology

0 comments :

Post a Comment