This is a RESTful API that manages notes. It can add, edit, delete, and show notes.
- This API only stores the data in an array variable. The data will be lost upon every restart.
- The current configuration allows CORS for all origins, which is insecure for production environments. You could implement authentication or configure the CORS securely yourself as workarounds.
Data example:
{
"id": "V1StGXR8_Z5jdHi6",
"title": "Sejarah JavaScript",
"createdAt": "2020-12-23T23:00:09.686Z",
"updatedAt": "2020-12-23T23:00:09.686Z",
"tags": ["NodeJS", "JavaScript"],
"body": "JavaScript pertama kali dikembangkan oleh Brendan Eich dari Netscape di bawah nama Mocha, yang nantinya namanya diganti menjadi LiveScript, dan akhirnya menjadi JavaScript. Navigator sebelumnya telah mendukung Java untuk lebih bisa dimanfaatkan para pemrogram yang non-Java.",
}
The id
, createdAt
, and updatedAt
properties are managed by the server.
The other properties are input by the client.
- Make sure you have
nvm
installed. If you don't have, install it using these commands below:-
You could skip this step if you would like to install NodeJS in the other way
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.5/install.sh | bash
-
- Install NodeJS v22.10.0 via nvm:
-
nvm install v22.10.0 nvm use v22.10.0
-
- Install packages required in the project directory:
- Open a terminal and change the directory to the project directory and type this command below:
npm install
- Open a terminal and change the directory to the project directory and type this command below:
Open a terminal and change the directory to the project directory.
-
Type this command to run the API:
npm run start:prod
It will start a web server running on host
0.0.0.0
, at port5000
(http://0.0.0.0:5000). -
Type this command to run the API:
npm run start:dev
It will start a web server running on host
localhost
, at port5000
(http://localhost:5000).
Request:
- Method: POST
- Endpoint: /notes
- Body Request:
{ "title": "Judul Catatan", "tags": ["Tag 1", "Tag 2"], "body": "Konten catatan" }
Response:
No. | Scenario | Status Code | Response Body |
---|---|---|---|
1 | The request succeeds | 201 (Created) |
|
2 | The request fails | 500 (Internal Server Error) |
|
Request:
- Method: GET
- Endpoint: /notes
Response:
No. | Scenario | Status Code | Response Body |
---|---|---|---|
1 | There are some notes | 200 (OK) |
|
2 | There are no notes |
|
Request:
- Method: GET
- Endpoint: /notes/{noteId}
Response:
No. | Scenario | Status Code | Response Body |
---|---|---|---|
1 | The note's id is found |
200 (OK) |
|
2 | The note's id is not found |
404 (Not Found) |
|
Request:
- Method: PUT
- Endpoint: /notes/{noteId}
- Body Request:
{ "title":"Judul Catatan Revisi", "tags":[ "Tag 1", "Tag 2" ], "body":"Konten catatan" }
Response:
No. | Scenario | Status Code | Response Body |
---|---|---|---|
1 | The note is successfully updated | 200 (OK) |
|
2 | The note's id is not found |
404 (Not found) |
|
Request:
- Method: DELETE
- Endpoint: /notes/{noteId}
Response:
No. | Scenario | Status Code | Response Body |
---|---|---|---|
1 | The note is successfully deleted | 200 (OK) |
|
2 | The note's id is not found |
404 (Not Found) |
|
curl -X {HTTP METHOD} -H "Content-Type: application/json" -d '{BODY REQUEST}' http://{host}:{port}{ENDPOINT}
The -H "Content-Type: application/json"
and -d
can be omitted if there is no body request passed on the request.
curl -X POST -H "Content-Type: application/json" -d '{"title": "Judul Catatan", "tags": ["Tag 1", "Tag 2"], "body": "Konten Catatan"}' http://0.0.0.0:5000/notes
curl -X GET http://localhost:5000/notes