Define an HTTP GET Endpoint for a Node.js API Server with Swagger

Will Button
InstructorWill Button

Share this video with your friends

Send Tweet
Published 6 years ago
Updated 4 months ago

In this lesson, you will learn how to create an HTTP GET endpoint for a node.js server using Swagger. This endpoint will be used to return all of the Todo items from Elasticsearch to the client.

Instructor: [0:00] Let's see if we can get rid of some of these red X's. Scroll back up to the top. The next thing I want to change is the title here. You can see as I'm typing in the editor on the left, that the UI on the right-hand pane is updating.

[0:17] Under paths, I want to get rid of all of that down to the Swagger endpoint. Now we're going to define our root path. The first thing it's going to accept is it's going to have a getEndpoint or it's going to accept getMethods.

[0:33] We'll give it a description and we'll say that this endpoint returns all the ToDos available in the database. It requires an operation ID. This is the function that will be called to fulfill this request.

[0:50] It's not going to have any parameters that it needs and the responses is, it's going to provide a 200 response. It's going to have a specific schema that's a type of array because it's going to be an array of those ToDo items that we defined in the model below. Those items, the way we specify that is using this dollar sign ref tag.

[1:14] Then we refer to it by referring to the definitions section and then ToDo. You can see with that that cleared up all of the red X's and we now have our first successful API endpoint.