httprequest

Return json body in REQUEST nodejs

痞子三分冷 提交于 2020-08-21 19:30:30
问题 I'm using the request module to make an HTTP GET request to an url in order to get a JSON response. However, my function is not returning the response's body. Can someone please help me with this? Here is my code: router.get('/:id', function(req, res) { var body= getJson(req.params.id); res.send(body); }); Here is my getJson function: function getJson(myid){ // Set the headers var headers = { 'User-Agent': 'Super Agent/0.0.1', 'Content-Type': 'application/x-www-form-urlencoded' } // Configure

Validating if request body in HTTP POST request is null in Spring Boot controller

天涯浪子 提交于 2020-08-10 20:15:07
问题 I am replacing manual validation of input to a POST request in a Spring Boot REST-controller. JSR-303 Spring Bean Validation is used for validating the instance variables in the request body and this is working as expected. What is the recommended method to validate that the object in the request body is not null? I have tried: annotating the entire object such as this: @NotNull @Valid @RequestBody Foo foo annotating the entire class with @NotNull I am replacing: @PostMapping... public