Skip to content

Latest commit

Β 

History

History
51 lines (44 loc) Β· 1.43 KB

File metadata and controls

51 lines (44 loc) Β· 1.43 KB

RESTful API Backend

Overview

RESTful API Backend berbasis Express.js dengan SQLite database. API ini menyediakan operasi CRUD untuk manajemen produk dengan validasi request, error handling terpusat, dan format response yang konsisten.

Project Structure

β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ app.js                 # Main Express application
β”‚   β”œβ”€β”€ database.js            # SQLite database setup
β”‚   β”œβ”€β”€ routes/
β”‚   β”‚   └── products.js        # Product CRUD routes
β”‚   └── middleware/
β”‚       β”œβ”€β”€ validation.js      # Request validation middleware
β”‚       └── errorHandler.js    # Centralized error handling
β”œβ”€β”€ data/
β”‚   └── database.sqlite        # SQLite database file
└── package.json

API Endpoints

Products

  • GET /api/products - Get all products (supports query: category, search, limit, offset)
  • GET /api/products/:id - Get product by ID
  • POST /api/products - Create new product
  • PUT /api/products/:id - Update product
  • DELETE /api/products/:id - Delete product

Response Format

All responses follow consistent JSON format:

{
  "success": true/false,
  "message": "Description",
  "data": {...}
}

Features

  • Request validation middleware
  • Centralized error handling
  • Consistent JSON response format
  • 404 handler for unknown routes
  • Query filtering and pagination

Running the Project

npm start

Server runs on port 5000.