(ML) M121DKX4633 – Dzaky Abdillah Salafy – UIN Sultan Syarif Kasim Riau
(ML) M260DSX2594 – Ahmad Habib Rizqi – Universitas Muhammadiyah Yogyakarta
(ML) M194DKX4708 – Akhmad Nur Fadhil – Universitas Islam Negeri Sultan Aji Muhammad Idris Samarinda
(CC) C038DSX0604 – Farhan Aly Hasbi – Institut Teknologi Sepuluh Nopember
(CC) C254DSX0785 – Rizal Nawang Pradana – Universitas Muhammadiyah Semarang
(MD) A304DSY1205 – Zainatul Sirti – Universitas Pembangunan Nasional Veteran Jakarta
This document provides information on how to use the API endpoints and their functionalities.
To run this project, install it locally using npm on your pc
# clone repository
$ git clone https://github.com/X-Detect/server-API-xdetect.git
# change directory to server-API-xdetect
$ cd server-API-xdetect
Please go to Google Cloud Console and create a service account with permissions for both Storage Object Admin and Storage Object Viewer
- Change configuration with your database (this app using Firebase) :
API_KEY=<YOUR_PRIVATE_KEY>
AUTH_DOMAIN=<YOUR_PRIVATE_KEY>
PROJECT_ID=<YOUR_PRIVATE_KEY>
STORAGE_BUCKET=<YOUR_PRIVATE_KEY>
MESSAGING_SENDER_ID=<YOUR_PRIVATE_KEY>
APP_ID=<YOUR_PRIVATE_KEY>
GOOGLE_CLOUD_PROJECT=<YOUR_CLOUD_PROJECT>
GOOGLE_APPLICATION_CREDENTIALS=<YOUR_PATH_TO_SERVICE_ACCOUNT>
This folder is used to store 2 file including firebase-config.js and serviceAccount.json. Use serviceAccount.json from Google Cloud Project
- Create firebase-config.js :
import { initializeApp } from 'firebase/app';
import { getAuth } from 'firebase/auth';
import { getFirestore } from 'firebase/firestore';
import dotenv from 'dotenv';
dotenv.config();
const firebaseConfig = {
apiKey: "",
authDomain: "",
projectId: "",
storageBucket: "",
messagingSenderId: "",
appId: ""
};
const app = initializeApp(firebaseConfig);
const auth = getAuth(app);
const db = getFirestore(app);
export { auth, db };
- locate in line 4 file handler.js
# in server-API-xdetect
# install all depencencies using `npm install`
# run the backend using `npm start` or if you want to use dev environment you can hit `npm run dev`
Route | HTTP Method | Description |
---|---|---|
/signup | POST | Sign up a new user |
/signin | POST | Sign in a user |
/signout | POST | Sign out a user |
/reset-password | POST | Reset user's password |
/users | GET | Get all users |
/users/:uid | GET | Get user by UID |
/upload-profile-picture | POST | Upload a profile picture for a user |
/upload/:uid | PUT | Upload a profile picture with UID |
/predict | POST | Perform a prediction using an uploaded image |
/article | POST | Post a new article |
/article | GET | Get all articles |
/article/:uid | GET | Get an article by UID |
Create a new user account.
- Method: POST
- Path: /signup
- Body Parameters:
{
"name": "John Doe",
"email": "johndoe@example.com",
"phone": "1234567890",
"password": "password123"
}
-
Success (HTTP 200):
- success (boolean):
true
- msg (string): "Berhasil SignUp, silakan SignIn"
- success (boolean):
-
Failure (HTTP 400):
- success (boolean):
false
- msg (string): "Email sudah terdaftar"
- success (boolean):
Authenticate and sign in a user.
- Method: POST
- Path: /signin
- Body Parameters:
{
"email": "johndoe@example.com",
"password": "password123"
}
-
Success (HTTP 200):
- success (boolean):
true
- msg (string): "Berhasil Sign In"
- data (object):
- uid (string): User's unique ID.
- email (string): User's email address.
- success (boolean):
-
Failure (HTTP 404):
- success (boolean):
false
- msg (string): "Error melakukan Sign In"
- success (boolean):
Send a password reset email to the user.
- Method: POST
- Path: /reset-password
- Body Parameters:
{
"email": "johndoe@example.com"
}
-
Success (HTTP 200):
- msg (string): "Link Reset Password Telah Dikirim Ke Email"
-
Failure (HTTP 200):
- msg (string): "Error melakukan reset password"
Sign out the currently authenticated user.
- Method: POST
- Path: /Signout
-
Success (HTTP 200):
- msg (string): "Sign out Berhasil"
-
Failure (HTTP 500):
- msg (string): "Gagal Melakukan Sign Out"
Upload an image file for prediction.
- Method: POST
- Path: /predict
- Body Parameters:
- image (file): Image file to be uploaded.
- Success (HTTP 200):
- status (string): "Success"
- message (string): "Profile picture berhasil ditambahkan"
- fileName (string): Name of the uploaded file.
- url (string): Public URL of the uploaded file.
- file (file): JSON file containing additional information.
Upload a profile picture image file.
- Method: POST
- Path: /upload-profile-picture
- Body Parameters:
- image (file): Image file to be uploaded.
- Success (HTTP 200):
- status (string): "Success"
- message (string): "Profile picture berhasil ditambahkan"
- fileName (string): Name of the uploaded file.
- url (string): Public URL of the uploaded file.
- file (file): JSON file containing additional information.
Upload a profile picture image file for a specific user.
- Method: POST
- Path: /upload/:uid
- Body Parameters:
- image (file): Image file to be uploaded.
- uid (string): User's unique ID.
- Route Parameters:
- uid (string): User's unique ID.
- Success (HTTP 200):
- status (string): "Success"
- message (string): "Profile picture berhasil ditambahkan"
- fileName (string): Name of the uploaded file.
- url (string): Public URL of the uploaded file.
- file (file): JSON file containing additional information.
Create and posting new artikel
- Method: POST
- Path: /article
- Body Parameters:
{
"imageURL": "https://example.com/image.jpg",
"title": "Judul Artikel",
"description": "Deskripsi artikel",
"createdBy": "John Doe",
"content": "Isi artikel...",
"sourceURL": "https://example.com/article"
}
- Success (HTTP 200):
- success (boolean): true
- msg (string): "Berhasil"
- Failure (HTTP 400):
- success (boolean): false
- msg (string): "Field berikut harus diisi: [field1, field2, ...]"
- Error (HTTP 500):
- success (boolean): false
- msg (string): "Terjadi kesalahan, tunggu beberapa saat"
- Method: GET
- Path: /article
- Body Parameters: none
- Success (HTTP 200):
- success (boolean): true
- msg (string): "Berhasil"
- Error (HTTP 500):
- success (boolean): false
- log : Error getting articles
- msg (string): "Terjadi kesalahan, tunggu beberapa saat"
{
"success": true,
"msg": "Berhasil",
"data": [
{
"id": "xdetect-article-abc",
"imageURL": "https://example.com/image.jpg",
"title": "Judul Artikel",
"description": "Deskripsi artikel",
"createdBy": "John Doe",
"createdAt": "June 10, 2023 10:00 AM",
"content": "Isi artikel...",
"sourceURL": "https://example.com/article"
},
{
"id": "xdetect-article-def",
"imageURL": "https://example.com/image2.jpg",
"title": "Judul Artikel 2",
"description": "Deskripsi artikel 2",
"createdBy": "Jane Smith",
"createdAt": "June 9, 2023 2:30 PM",
"content": "Isi artikel 2...",
"sourceURL": "https://example.com/article2"
}
]
}
- Method: POST
- Path: /article/:uid
- Route Parameters:
- uid (string): Articles's unique ID.
- Success (HTTP 200):
- success (boolean): true
- msg (string): "Berhasil"
- data (object): Data artikel yang ditemukan
- Not Found (HTTP 404):
- success (boolean): false
- msg (string): "Artikel tidak ditemukan"
- Error (HTTP 500):
- success (boolean): false
- msg (string): "Terjadi kesalahan, tunggu beberapa saat"
{
"success": true,
"msg": "Berhasil",
"data": {
"id": "xdetect-article-abc",
"imageURL": "https://example.com/image.jpg",
"title": "Judul Artikel",
"description": "Deskripsi artikel",
"createdBy": "John Doe",
"createdAt": "June 10, 2023 10:00 AM",
"content": "Isi artikel...",
"sourceURL": "https://example.com/article"
}
}
This endpoint is used to retrieve a list of users.
- Method: GET
- Path: /users
- Body Parameters: No parameters are required.
- Success (HTTP 200):
- success (boolean): true
- msg (string): "Berhasil"
- Error (HTTP 500):
- success (boolean): false
- log : Error getting articles
- msg (string): "Terjadi kesalahan, tunggu beberapa saat"
{
"success": true,
"msg": "Success",
"data": [
{
"id": "1",
"name": "John Doe",
"email": "johndoe@example.com"
},
{
"id": "2",
"name": "Jane Smith",
"email": "janesmith@example.com"
}
]
}
-
Method: GET
-
Path: /users/:uid
-
Route Parameters:
- uid (string): The User ID (UID) of the user to retrieve.
-
Example Request: GET /users/alkdmfoIY12kfjb
- Success (HTTP 200):
- success (boolean): true
- msg (string): "Berhasil"
- data (object): Data user yang ditemukan
- Not Found (HTTP 404):
- success (boolean): false
- msg (string): "User tidak ditemukan"
- Error (HTTP 500):
- success (boolean): false
- msg (string): "Terjadi kesalahan, tunggu beberapa saat"
{
"success": true,
"msg": "Success",
"data": {
"id": "1",
"name": "John Doe",
"email": "johndoe@example.com"
}
}