Issue
I have an API to be designed, this one require only one parameter then to be inserted into DB. So POST is the verb, but my doubt is on the parameter that will be passed as query param or path param ?
@RequestMapping(value = "/users-access/{userId}", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseStatus(HttpStatus.NO_CONTENT)
@ApiOperation("Promotes user access")
public boolean promoteUserAccess(@PathVariable String userId)
throws BadRequestException, UnAuthorizedException {
//actions
}
What's the best practices ? thanks !
Solution
You should send your data in the request body like below.
@RequestMapping(value = "/users", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseStatus(HttpStatus.NO_CONTENT)
@ApiOperation("Promotes user access")
public boolean promoteUserAccess(@RequestBody Request request)
throws BadRequestException, UnAuthorizedException {
//actions
}
public class Request {
private String userId;
}
Answered By - javaguy