Create a Node.js function for an HTTP PUT request for a Swagger API

Will Button
InstructorWill Button

Share this video with your friends

Send Tweet

This lesson will teach you how to update a Todo item in Elasticsearch when received from an HTTP PUT method in your API server built with Swagger.

Victor Hazbun
Victor Hazbun
~ 4 years ago

I got this when trying to do a PUT request to the API, I already installed and setup cors. Can you please help me getting this working? TY.

{"message":"Response validation failed: void does not allow a value","code":"INVALID_TYPE","failedValidation":true,"path":["paths","/todo/{id}","put","responses","200"],"originalResponse":"{}"}
~ 4 years ago

I was not able to end the response with res.end(). I got a JSON parsing error. So I sent back the response. Then I got Victor Alonso's error. I changed the swagger specs to:

           description: "Todo updated"
              title: reset
                  type: string
           description: "Yikes! An error!"
  x-swagger-router-controller: "UpdateTodoById"

as indicated at

What exactly am I doing??? Not clear :-(