API Documentation

1. Provinces API

Endpoint: /api/provinces

Method: GET

This API returns a list of all provinces. You can optionally filter by province code.

Parameters:

  • province_code (optional): Filter provinces by a specific province code.

Response:

Returns a JSON object with a success boolean and a data array of province objects.

{
  "success": true,
  "data": [
    {
      "province_code": "01",
      "name": "Thành phố Hà Nội",
      "short_name": "Hà Nội",
      "code": "HN",
      "place_type": "Thành phố",
      "wards": [...]
    },
    // ... more provinces
  ]
}

Example Usage:

Fetch all provinces:

fetch('/api/provinces')
  .then(response => response.json())
  .then(data => console.log(data));

Fetch province with code '01':

fetch('/api/provinces?province_code=01')
  .then(response => response.json())
  .then(data => console.log(data));
2. Wards API

Endpoint: /api/wards

Method: GET

This API returns a list of all wards. You can filter by province code and limit the number of results.

Parameters:

  • province_code (optional): Filter wards belonging to a specific province code.
  • limit (optional): Limit the number of wards returned.

Response:

Returns a JSON object with a success boolean and a data array of ward objects.

{
  "success": true,
  "data": [
    {
      "ward_code": "00001",
      "name": "Phường Phúc Xá",
      "province_code": "01"
    },
    // ... more wards
  ]
}

Example Usage:

Fetch all wards:

fetch('/api/wards')
  .then(response => response.json())
  .then(data => console.log(data));

Fetch wards for province code '01':

fetch('/api/wards?province_code=01')
  .then(response => response.json())
  .then(data => console.log(data));

Fetch 50 wards for province code '01':

fetch('/api/wards?province_code=01&limit=50')
  .then(response => response.json())
  .then(data => console.log(data));

CORS Policy: These APIs are configured with Access-Control-Allow-Origin: *, allowing cross-origin requests from any domain.