debtwriter-api
This is a RESTful API project built with Express and using MongoDB as the database. The project is designed to manage information about personal debts.
- Add user/debt
- Update user / debt information
- Delete user / debt
- Get user / debt information
Clone the project
git clone [https://github.com/mwahyudihd/debtwriter-api.git](debtwriter-api.git)
Go to the project directory
cd debtwriter-api
Install dependencies
npm install
- db : app/config/database change mongodb://127.0.0.1:27017/(with your local database)
- port : default [3000] and can change with port variable at server.js
Start the server
npm run dev
Here are some of the available endpoints in the debtwriter-api:
- Endpoint:
POST http://127.0.0.1:YOUR_PORT/debt-api/items
Description: Creating new user.
Parameter | Type | Description |
---|---|---|
user |
string |
Required. Key of items |
debt |
string |
Required. Key of items |
Model:
{
"username": "user123",
"password": "password",
"nama": "John Does",
"role": "member",
}
{
"pencatat": "60d0fe4f5311236168a109ca",
"pemberi": "Jhon",
"jumlah": 5000.00,
"tgl_hutang": "2024-06-14T00:00:00.000Z",
"lunas_pada": null,
"deadline": "2024-07-14T00:00:00.000Z",
"catatan": "Hutang untuk peminjaman",
"status": "belum lunas",
"create_on": "2024-06-14T12:45:32.000Z"
}
- Endpoint:
GET http://127.0.0.1:YOUR_PORT/debt-api/items/${id}
Description: Getting information data with ID.
Parameter | Type | Description |
---|---|---|
id |
objectId |
Required. Id of item to fetch |
- Endpoint:
GET http://127.0.0.1:YOUR_PORT/debt-api/items
Description: Getting All data of items.
Parameter | Type | Description |
---|---|---|
user |
string |
Required. Key of items |
debt |
string |
Required. Key of items |
- Endpoint:
PUT http://127.0.0.1:YOUR_PORT/debt-api/items/${id}
Description: Updating data by ID.
Parameter | Type | Description |
---|---|---|
id |
objectId |
Required. Id of item to modify |
Note: attributes to be updated optional can be entered and not e.g. you can update user / debt data without entering attributes and password values etc. |
- Endpoint:
DELETE http://127.0.0.1:YOUR_PORT/debt-api/items/${id}
Description: Removing data by ID.
Parameter | Type | Description |
---|---|---|
id |
objectId |
Required. Id of item to remove |
const apiUrl = 'http://127.0.0.1:YOUR_PORT/debt-api/items'; // fetch(apiUrl)
.then(response => {
if (!response.ok) {
throw new Error('Network response was not ok');
}
return response.json();
})
.then(data => {
console.log('Data from API:', data);
})
.catch(error => {
console.error('Error:', error);
});
If you want to contribute, please make a pull request for contribution.