This API allows users to manage your money lends. I tried to code this with little reference to understand node better, so if any correction , feel free to fork it and push the changes
- Clone the repository to your local machine.
- Run
npm install
to install dependencies. - Create a
.env
file in the root directory and add the following variables:PORT=3000 NODE_ENV=(production or deployment) MONGODB_URI=<your_mongodb_uri> SECRET_KEY=<your_secret_key_for_jwt>
- Start the server by running
npm start
ornodemon server.js
.
pull from dockerhub and run your container
```
docker pull shettyarjun/money_lender
docker images
docker run -d -p 3000:3000 shettyarjun/money_lender
docker ps
In postman http://localhost:3000 and perform the request
docker stop <container_id or container_name>
docker rm <container_id or container_name>
```
Endpoints for (http://localhost:3000)
POST /api/users/register
{
"username": "testuser",
"email": "test@example.com",
"password": "testpassword"
}
{
"_id": "60a6f2c6a022d51f30576b4b",
"username": "testuser",
"email": "test@example.com"
}
POST /api/users/login
{
"email": "test@example.com",
"password": "testpassword"
}
{
"accesstoken": "<your_access_token>"
}
GET /api/users/profile
Authorization: Bearer <your_access_token>
{
"_id": "60a6f2c6a022d51f30576b4b",
"username": "testuser",
"email": "test@example.com"
}
POST /api/moneylends
{
"name": "Friend",
"money_taken": 100,
"money_given": 0,
"date": "2023-05-20"
}
Authorization: Bearer <your_access_token>
{
"_id": "60a6f2c6a022d51f30576b4c",
"name": "Friend",
"money_taken": 100,
"money_given": 0,
"date": "2023-05-20"
}
PUT /api/moneylends/:id
id: 60a6f2c6a022d51f30576b4c
{
"money_given": 50
}
Authorization: Bearer <your_access_token>
{
"_id": "60a6f2c6a022d51f30576b4c",
"name": "Friend",
"money_taken": 100,
"money_given": 50,
"date": "2023-05-20"
}
DELETE /api/moneylends/:id
id: 60a6f2c6a022d51f30576b4c
Authorization: Bearer <your_access_token>
{
"message": "Money lend has been deleted"
}