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
.envfor your environmentecho DATABASE_URL="postgresql://postgres:password@localhost:5433/locations" > .env
The above
DATABASE_URLis 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 devormigrate deploywill work cleanly. -
-
Start development server
npm run dev
-
Build application
npm run build
-
Start production server
npm run start
GET /v1/countries- Get all countriesGET /v1/countries/:id- Get country by ID
GET /v1/regions- Get all regionsGET /v1/regions/:regionCode- Get region by codeGET /v1/regions/:regionCode/districts- Get districts in a region
GET /v1/districts- Get all districtsGET /v1/districts/:districtCode- Get district by codeGET /v1/districts/:districtCode/wards- Get wards in a district
GET /v1/wards- Get all wardsGET /v1/wards/:wardCode- Get ward by codeGET /v1/wards/:wardCode/places- Get places in a ward
GET /v1/places- Get all placesGET /v1/places/:id- Get place by ID
GET /v1/search?q=nzuguni- Fulltext search for locations by name
npm testThis project is licensed under the CopyLeft License โ see the LICENSE file for details.