This repository contains a Node.js/Express solution for the DPDzero API assignment, the assignment requirements and the API endpoint documentation can be found here
-
The backend is written in JavaScript (Node.js). Express is the framework of choice due to the following reasons:
- Excellent Community support
- Easy to write middleware
- Large number of utility packages and libraries, courtesy of npm
- Wide selection of ORMs (This project uses Prisma)
-
This project uses PostgreSQL as the database. As this project uses Prisma ORM, it can be easily replaced with any other database supported by Prisma by simply changing the provider in
schema.prisma
file, editing theDATABASE_URL
environment variable indocker-compose.yml
with the correct connection string and making other necessary changes.The database schema is as follows:
- Users Table to store the registered users' data
CREATE TABLE "Users" ( "user_id" SERIAL NOT NULL, "username" TEXT NOT NULL, "email" TEXT NOT NULL, "password" TEXT NOT NULL, "full_name" TEXT NOT NULL, "age" INTEGER NOT NULL, "gender" TEXT NOT NULL, CONSTRAINT "Users_pkey" PRIMARY KEY ("user_id") );
- kvPairData table to store the key value pairs inserted by the users
CREATE TABLE "kvPairData" ( "key" TEXT NOT NULL, "value" TEXT NOT NULL, CONSTRAINT "kvPairData_pkey" PRIMARY KEY ("key") );
To set up the project locally, follow these simple steps.
- Make sure that Docker is installed and it is running.
-
Clone the repo
git clone https://github.com/sumad200/DPDzero_Task.git
-
Navigate to the project directory
cd DPDzero_Task
-
Ensure that docker daemon is running and execute the following command to build the images
docker compose up
This may take a few minutes.
-
Once the containers are up and running, the last output in the terminal should be as follows:
dpdzero_task-api-1 | DPD Zero Task Running on port 6900
-
The application can now be accessed on port
6900
on your host machine.
If the setup was successful, visiting http://localhost:6900/ on your web browser or making a GET
request to http://localhost:6900/ should return the following JSON response:
{
"hello": "dpdZero task running"
}
If you get the above response, you have successfully set up the project locally and can make requests to the API, the documentation for the available endpoints can be viewed here. It is recommended to use an API client like Postman or Insomnia to make requests easily.