An example of a REST API built with Express, for self-education.
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.
.editorconfig First commit, no functionality yet. Apr 17, 2016
router.js Added caching for GET requests on individual element views. Dec 4, 2016

HTML Reference API

An example of a REST API built with Express and MongoDB, for self-education. A lot of this was learned from the book Web Development with Node & Express by Ethan Brown, and the article Build a RESTful API Using Node and Express 4 by Chris Sevilleja.

This simply returns JSON; for the associated front-end client, check out html-reference-webapp. Currently it's used to store data on HTML elements (html, head, body, etc.) though the only data stored at the moment is a name and description for each element.


If you want to run this locally you'll need a MongoDB database. I used a free sandbox database hosted on mLab, but anything starting with mongodb:// should work fine, probably. The app expects there to be a credentials.js file in the base directory with MongoDB URLs, like this:

module.exports = {
    mongo: {
        development: {
            connectionString: "mongodb://<your-mongodb-instance>"
        production: {
            connectionString: "mongodb://<your-mongodb-instance>"

Once you've added that, and assuming you already have Node installed, navigate to the base directory with a command line interface and do this:

npm install

That will start the API server, and the main html-reference-api.js file will also be watched for changes. When any changes are saved, the Mocha test suite will run to test those changes. The test suite can also be run manually (assuming the API server is already running) from the project root directory like so, if you have Mocha globally installed:

mocha tests

Supported Routes

Once the application is running, the following routes are available:

Route Request Method Action
/api/elements GET View all elements
/api/elements POST Add a new element
/api/element/:element_id GET View a specific element
/api/element/:element_id PUT Update a specific element
/api/element/:element_id DELETE Delete a specific element