Building a Basic Todo List REST API in Node.js with Express

ACT
67.9K views

Open Source Your Knowledge, Become a Contributor

Technology knowledge has to be shared and made accessible for free. Join the movement.

Create Content

Content Negotiation

Express allows to do content-negotiation. Using response.format function, it can perform content-negotiation on the Accept HTTP header on the request object, when present.

It uses request.accepts() to select a handler for the request, based on the acceptable types ordered by their quality values. If the header is not specified, the first callback is invoked. When no match is found, the server responds with 406 “Not Acceptable”, or invokes the default callback.

(adapted from http://expressjs.com/en/api.html)

Content Negotiation Example

Web Template - EJS

EJS is an embedded JavaScript template engine. Here are the some of the main features:

  • Control flow with <% %>
  • Escaped output with <%= %> (escape function configurable)
  • Unescaped raw output with <%- %>
  • Includes
  • Client-side support
  • Complies with the Express view system

For more information, you can visit: https://www.npmjs.com/package/ejs

To use it, it has to be installed:

npm install ejs
Exercise: Complete the Basic EJS Example

Now, we have see the main parts on how to do a todo list with Node.js, let's wrap up!

Open Source Your Knowledge: become a Contributor and help others learn. Create New Content