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

Will Button
InstructorWill Button
Share this video with your friends

Social Share Links

Send Tweet
Published 8 years ago
Updated 2 years 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.

egghead
egghead
~ 5 minutes ago

Member comments are a way for members to communicate, interact, and ask questions about a lesson.

The instructor or someone from the community might respond to your question Here are a few basic guidelines to commenting on egghead.io

Be on-Topic

Comments are for discussing a lesson. If you're having a general issue with the website functionality, please contact us at support@egghead.io.

Avoid meta-discussion

  • This was great!
  • This was horrible!
  • I didn't like this because it didn't match my skill level.
  • +1 It will likely be deleted as spam.

Code Problems?

Should be accompanied by code! Codesandbox or Stackblitz provide a way to share code and discuss it in context

Details and Context

Vague question? Vague answer. Any details and context you can provide will lure more interesting answers!

Markdown supported.
Become a member to join the discussionEnroll Today