A RESTful API for Tanzania location data including countries, regions, districts, wards, and places.
- Hierarchical location data with proper relationships
- RESTful API with clean structure
- Input validation and error handling
- Pagination and search support
- Node.js / Express
- PostgreSQL
- Prisma ORM
- Jest & Supertest for testing
- Node.js LTS
- Tanzania Locations Database running ๐๐ฟโโ๏ธ๐๐ฟโโ๏ธ
- npm or yarn
-
Clone the repository
git clone https://github.com/yourusername/locations-API.git cd locations-API
-
Install dependencies
npm install
-
Create
.env
for your environmentecho DATABASE_URL="postgresql://postgres:password@localhost:5433/locations" > .env
The above
DATABASE_URL
is for the Tanzania-locations-database Docker container provision. -
Sync up your API with the locations database:
-
a. Pull existing DB schema into your Prisma schema
pnpx prisma db pull
-
b. Create migration init files
mkdir prisma/migrations/init
-
c. Mark the current schema as baseline
pnpx prisma migrate diff \ --from-empty \ --to-schema-datamodel prisma/schema.prisma \ --script > prisma/migrations/init/migration.sql
-
d. Create migration history manually
pnpx prisma migrate resolve --applied init
โ Now you're synced! Future
prisma migrate dev
ormigrate deploy
will work cleanly. -
-
Start development server
npm run dev
-
Build application
npm run build
-
Start production server
npm run start
GET /api/countries
- Get all countriesGET /api/countries/:id
- Get country by ID
GET /api/regions
- Get all regionsGET /api/regions/:regionCode
- Get region by codeGET /api/regions/:regionCode/districts
- Get districts in a region
GET /api/districts
- Get all districtsGET /api/districts/:districtCode
- Get district by codeGET /api/districts/:districtCode/wards
- Get wards in a district
GET /api/wards
- Get all wardsGET /api/wards/:wardCode
- Get ward by codeGET /api/wards/:wardCode/places
- Get places in a ward
GET /api/places
- Get all placesGET /api/places/:id
- Get place by ID
npm test
This project is licensed under the CopyLeft License โ see the LICENSE file for details.