REST API Requirements – Node.js API with TDD Tutorial

To demonstrate the Node.js API development, in this tutorial, we will create a system for storing and retrieving customer information. We can call it Customer Information System. Eventually, we will use Node.js, Express.js, and MongoDB to create it as a RESTful service, which we can name it as Customer Service.

The system will have specific functionalities to manage customer information. These functionalities of the system can be exposed through API, which will be built into the system itself.

REST API Functionalities

In our system, the first thing we have to do is functionality to add a new customer. Then we can update an existing customer detail. Once we have created the customer and eventually we want to read the customer detail, we can also get a list of customers from our system.

Below are the different functionalities or operations or end-points that we can create in our Customer Service RESTful API.

1. Add Customer API

In this API endpoint, we have to send a new customer detail in the request and the service will create the customer in the system. Once the customer creation is complete, the API will respond with the newly created customer detail. Here is the requirement specification for this API.

HTTP Method POST
API Endpoint /customers
Request Path Parameter None
Request Query Parameter None
Request Body Customer Details
Response Body Created Customer Details
Response Status 201

2. Get Customer List API

With this API endpoint, we will be able to get a list of customers. This API endpoint will also have searching, filtering, and paging features. So that can search for customers with particular search criteria, apply some filtering conditions, and we can even get the result with pagination. Requirement specification for this functionality is as below.

HTTP Method GET
API Endpoint /customers
Request Path Parameter None
Request Query Parameter None
Request Body None
Response Body Fetched Customers List
Response Status 200

3. Get Customer API

Once the customer has been created or modified, we can get the detail for a particular customer via this API endpoint. Requirement specification for this functionality is as below.

HTTP Method GET
API Endpoint /customers/:customerId
Request Path Parameter customerId
Request Query Parameter None
Request Body None
Response Body Fetched Customer Details
Response Status 200

4. Modify Customer API

 In this operation, we will send the modified customer detail in the request to be persisted in the storage. Like the add customer API, this will also respond the modified customer detail in the response once it’s completed the request. Requirement specification for this functionality is as below.

HTTP Method PUT
API Endpoint /customers/:customerId
Request Path Parameter customerId
Request Query Parameter None
Request Body Customer Details
Response Body Modified Customer Details
Response Status 200

5. Remove Customer API

 We can also delete a customer from our system using this API endpoint. Once the customer has been removed from the system, this will respond with the customer detail back to the requested system. Requirement specification for this functionality is as below.

HTTP Method DELETE
API Endpoint /customers/:customerId
Request Path Parameter customerId
Request Query Parameter None
Request Body None
Response Body Removed Customer Details
Response Status 200

Customer Details

Since our system’s primary purpose is to collect, store and retrieve the customer information, we need to define all fields or attributes of the customer information. The below table shows the attributes that we want to store in the storage for a customer. 

Also, field type required flag and any constraints of each attribute. This additional information is essential so that the system can be designed, developed, and tested robustly.

Field Name Field Type Required? Constraints
First Name Text Required Minimum  2 Characters
Last Name Text Required Minimum  1 Character
Email Text Required Valid Email
Phone Number Number Required Valid  Phone Number
Address Text Not Required
City Text Not Required
State Text Not Required
Zip Code Number Not Required
Country Text Not Required

Please check out the index page for this Node.js RESTful API development with TDD approach tutorial with all the posts in sequence in one place.

This blog post is an excerpt from the book Building Node.js REST API with TDD approach. Please check out the link for more information.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.