Algorithm Mock tes on Folder algorithm-test
This is my project Backend API Todolist with tech stack nodeJs, ExpressJs, Postgres
The module nodejs used are in package.json
file.
index.js
used to run the service
npm install
npx prisma migrate dev
npm run start
The REST API to the todolist app is described below.
POST /api/v1/auth/register HTTP/1.1
Content-Type: application/json
Host: binar-algorithm-fsw-mock-test-production.up.railway.app
Content-Length: 69
{
"name": "user",
"email": "[email protected]",
"password": "123123"
}
POST /api/v1/auth/login HTTP/1.1
Content-Type: application/json
Host: binar-algorithm-fsw-mock-test-production.up.railway.app
Content-Length: 52
{
"email": "[email protected]",
"password": "123123"
}
You will get a token that will be used to get authorization to perform CRUD todolist
GET /api/v1/auth/whoami HTTP/1.1
Authorization: yourAuthorization (token from jwt)
Host: binar-algorithm-fsw-mock-test-production.up.railway.app
POST /api/v1/auth/logout HTTP/1.1
Authorization: yourAuthorization (token from jwt)
Host: binar-algorithm-fsw-mock-test-production.up.railway.app
GET /api/v1/todo HTTP/1.1
Content-Type: application/json
Authorization: yourAuthorization (token from jwt)
Host: binar-algorithm-fsw-mock-test-production.up.railway.app
POST /api/v1/todo HTTP/1.1
Content-Type: application/json
Authorization: yourAuthorization (token from jwt)
Host: binar-algorithm-fsw-mock-test-production.up.railway.app
Content-Length: 176
{
"task": "binar user",
"description": "pembahasan tentang media handling",
"start": "2023-11-22T08:09:59.908Z",
"finish": "2023-11-22T08:09:59.908Z",
"status": "proses"
}
PUT /api/v1/todo/3 HTTP/1.1
Content-Type: application/json
Authorization: yourAuthorization (token from jwt)
Host: binar-algorithm-fsw-mock-test-production.up.railway.app
Content-Length: 177
{
"task": "belajar binar update",
"description": "pembahasan tentang media",
"start": "2023-11-22T08:10:48.451Z",
"finish": "2023-11-22T08:10:48.452Z",
"status": "proses"
}
DELETE /api/v1/todo/3 HTTP/1.1
Content-Type: application/json
Authorization: yourAuthorization (token from jwt)
Host: binar-algorithm-fsw-mock-test-production.up.railway.app
GET /api/v1/todo HTTP/1.1
Content-Type: application/json
Authorization: yourAuthorization (token from jwt when login)
Host: binar-algorithm-fsw-mock-test-production.up.railway.app
Apakah Kegunaan JSON pada REST API?
JSON digunakan sebagai format pertukaran data standar di REST API. Ketika klien mengirimkan permintaan HTTP kepada server atau ketika server mengirimkan respons, data seringkali diwakili dalam format JSON. Ini membuat proses pertukaran data antara klien dan server lebih efisien dan konsisten.
Jelaskan bagaimana REST API bekerja
RESTful API bekerja dengan cara memanipulasi resource dan representasi. Representasi ini saling dipertukarkan di antara pengguna dan server melalui antarmuka terstandar dan protokol komunikasi tertentu, biasanya HTTP.
REST API menggunakan metode HTTP (GET, POST, PUT, DELETE) untuk berinteraksi dengan sumber daya.
Metode HTTP memberikan operasi umum yang dapat diaplikasikan pada sumber daya:
GET: Mendapatkan data dari sumber daya.
POST: Membuat sumber daya baru.
PUT atau PATCH: Memperbarui sumber daya yang sudah ada.
DELETE: Menghapus sumber daya.