Skip to content

sumbangngalor/testing-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Patient Data API

A simple Express.js REST API with dummy patient data for testing and development purposes.

Features

  • 20 example patient records with Indonesian names and data
  • Full CRUD operations (Create, Read, Update, Delete)
  • RESTful API endpoints
  • CORS enabled
  • JSON responses

Installation

  1. Install dependencies:
npm install
  1. Start the server:
npm start

The server will run on http://localhost:3002

API Endpoints

Base URL: http://localhost:3002

Method Endpoint Description
GET / API information and documentation
GET /patients Get all patients (supports pagination)
GET /patients/:id Get patient by ID
POST /patients Create new patient
PUT /patients/:id Update patient by ID
DELETE /patients/:id Delete patient by ID

Pagination

The /patients endpoint supports pagination with the following query parameters:

  • page: Page number (default: 1, minimum: 1)
  • limit: Number of records per page (default: 10, maximum: 50, minimum: 1)

Pagination Response Format

{
  "success": true,
  "count": 10,
  "total": 20,
  "pagination": {
    "current": 1,
    "total": 2,
    "hasNext": true,
    "hasPrev": false,
    "limit": 10,
    "next": 2
  },
  "data": [...]
}

Patient Data Structure

Each patient record contains:

{
  "id": 1,
  "nama": "Ahmad Subandi",
  "namaIbuKandung": "Siti Aminah",
  "tempatLahir": "Jakarta",
  "tanggalLahir": "1985-03-15",
  "namaAyah": "Budiman Subandi",
  "noTelepon": "081234567890",
  "statusPernikahan": "Menikah",
  "agama": "Islam",
  "pendidikan": "S1",
  "sukuBangsa": "Jawa",
  "golonganDarah": "A+",
  "alamat": "Jl. Sudirman No. 123, Jakarta Selatan"
}

Example Usage

Get all patients:

curl http://localhost:3002/patients

Get patients with pagination:

# Get first page (10 patients)
curl http://localhost:3002/patients?page=1&limit=10

# Get second page (10 patients)
curl http://localhost:3002/patients?page=2&limit=10

# Get first page with 5 patients only
curl http://localhost:3002/patients?page=1&limit=5

Get patient by ID:

curl http://localhost:3002/patients/1

Create new patient:

curl -X POST http://localhost:3002/patients \
  -H "Content-Type: application/json" \
  -d '{
    "nama": "John Doe",
    "namaIbuKandung": "Jane Doe",
    "tempatLahir": "Jakarta",
    "tanggalLahir": "1990-01-01",
    "namaAyah": "Jack Doe",
    "noTelepon": "081234567890",
    "statusPernikahan": "Belum Menikah",
    "agama": "Islam",
    "pendidikan": "S1",
    "sukuBangsa": "Jawa",
    "golonganDarah": "A+",
    "alamat": "Jl. Example No. 123"
  }'

Update patient:

curl -X PUT http://localhost:3002/patients/1 \
  -H "Content-Type: application/json" \
  -d '{
    "nama": "Ahmad Subandi Updated",
    "statusPernikahan": "Menikah"
  }'

Delete patient:

curl -X DELETE http://localhost:3002/patients/1

Sample Data

The API includes 20 sample patient records with diverse Indonesian names, representing various:

  • Ethnic backgrounds (Jawa, Batak, Sunda, Melayu, Bugis, Dayak, etc.)
  • Religions (Islam, Kristen, Hindu, Buddha)
  • Education levels (SMA, D3, S1, S2)
  • Blood types (A+, A-, B+, B-, AB+, AB-, O+, O-)
  • Marital statuses (Menikah, Belum Menikah)
  • Cities across Indonesia

Development

  • Built with Express.js
  • Data separated into datas.js for better organization
  • Uses in-memory data storage (data resets on server restart)
  • CORS enabled for cross-origin requests
  • JSON request/response format

Project Structure

test-api/
├── server.js    # Main Express.js server and API routes
├── datas.js     # Patient data
├── package.json # Dependencies and scripts
└── README.md    # This file

License

MIT

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published