Part 1: A Complete Guide to Building a RESTful API using Node, Express and MongoDB (An Overview)

Build and Deploy an App and everything else in the process.

Sylva Elendu
Facebook Developer Circles Lagos
4 min readJun 9, 2018

--

How do you like your meal, please?

This is the first part of this series.

You can get a lot done using Google and Stack Overflow, however if you have never built a simple API prior to this moment, you will have to read through tons of articles as well as spend tons of hours on Stack Overflow figuring your way around. The aim of this article is to simplify that process.

There are tons of resources available on the internet to guide you through your learning phase, but then again, these resources cover different parts of the whole. You hardly find one that actually guides you from start to finish except for the premium contents. When I built my first API, I had to consume so much resources which was fun by the way, but took so much time trying to get the work done.

I should mention here that there are two primary reasons I am writing this article. Firstly, to help you understand the process involved in building an API from user stories, to development, to deploying and documentation. Secondly, to help you keep in mind the impportance of writing clean code. In this vein, we will be developing with the following in mind: ES6 and above, Airbnb style guide for ES6, continuous integration and badge.

Why do I have the feeling that you know what an API is? Well, if you don’t, here’s an awesome place to start, click here and here. To know more about the fancy adjective (RESTful API), simply click here and here for that.

This guide is actually a series covering all you need to know from setting up your development environment to deploying and finally documenting your API. I will include a number of helpful URLs for better understanding of concepts we will be working with. So, with these out of the way, let’s talk a bit about the application we’ll be building.

We will be building the API for an application we will call Support. The aim of Support is simple; provide a platform where anyone can show support for causes they believe in. The potential of this application is actually limitless especially when you imagine that this cause can cover literally anything, from natural disasters such as floods and landslides to social campaigns, and this list goes on. Basically, it allows people build a supportive community around a given cause hence making the world a better place.

Now, let’s discuss the features of our application. I will be creating a simple user story for our application. To learn more about writing user stories, please click here.

Here is our user story,

  1. As a user, I want to sign up and login to the platform.
  2. As a logged-in (authenticated) user, I want to create a new cause, edit and delete the content of the cause when I decide to.
  3. As a user (not authenticated), I want to access created causes on the platform as well as comments/reviews done on each cause.
  4. As an authenticated user, I want to access my profile as well as the profile of others on the platforms.

We can add a lot of features to our application, but at the moment, let’s focus on building our first MVP. This user story is not detailed enough, we don’t want to spend too much time on it. There could be more, for an example, a user should expect some form of verification by email or SMS at signup, search for causes without having to look through a long list, be able to upload personal photos as well as photos for causes created.

I should mention that user verification may not seem to be important to the user at signup, but in reality, it is actually important to authenticate your users if for nothing else, to provide assistance when the user needs to do a password-reset or forgets password.

Here’s how this project will work:

Part 1 (which is this): Defining and understanding the scope of our application.

Part 2: Setting up our development environment. See here.

Part 3: Developing CRUD operations. See here.

Part 4: Deploying to mLab and Heroku. See here.

Part 5: Adding user authentication. See here.

Part 6: Documentation with Swagger. See here.

I will update the links to the several parts as soon as it is live.

Final notes: This API will be developed using JavaScript. This means we will be using the following technologies:

NodeJS: This is a cross-platform run-time environment built on Chrome’s V8 JavaScript engine used in running JavaScript codes on the server. It allows for installation and managing of dependencies and communication with databases.

ExpressJS: This is the web application framework for NodeJS.

MongoDB: This is a free open source NOSQL document database with scalability and flexibility. Data are stored in flexible JSON-like documents

React: A JavaScript library for building user interfaces. We will be using this, If we need to build the front end.

Oh one more thing, a special shout-out goes to Scotch.io, Freecodecamp, Stack Overflow, Traversy Media, Academind and a host of other extremely helpful blogs.

To read part 2, click here.

Thanks for reading. Kindly CLAP and SHARE, if this article was useful to you.

--

--