A Laravel-based Indonesian shipping cost API that provides access to province, city, district, and subdistrict data with fallback support between local database and external API services.
- Dual Data Source: Automatically checks local database first, falls back to external API if needed
- Request Logging: All API calls are logged with performance metrics and source tracking
- Consistent Response Format: Unified JSON response structure across all endpoints
- Rate Limiting: Built-in protection against API abuse
- Error Handling: Comprehensive error handling with detailed logging
Traditional RajaOngkir-compatible responses using local database only.
Modern API with enhanced features:
- Database-first approach with API fallback
- Consistent response format with
metaanddatastructure - Performance optimized with local data caching
- Comprehensive request logging
https://ongkir.velocitydeveloper.id/api/v2
Include your API key in the request headers:
Authorization: Bearer YOUR_API_KEY
All V2 endpoints return responses in the following format:
{
"meta": {
"message": "Success Get [Resource]",
"code": 200,
"status": "success"
},
"data": [...]
}Get All Provinces
GET /v2/province
Get Province by ID
GET /v2/province?id={province_id}
Example Response:
{
"meta": {
"message": "Success Get Province",
"code": 200,
"status": "success"
},
"data": [
{
"province_id": "1",
"province": "Bali"
}
]
}Get All Cities
GET /v2/city
Get Cities by Province
GET /v2/city/{province_id}
GET /v2/city?province={province_id}
Get City by ID
GET /v2/city?id={city_id}
Example Response:
{
"meta": {
"message": "Success Get City",
"code": 200,
"status": "success"
},
"data": [
{
"city_id": "17",
"type": "Kabupaten",
"city_name": "Badung",
"postal_code": "80351",
"province_id": "1",
"province": "Bali"
}
]
}Get All Districts
GET /v2/district
Get Districts by City
GET /v2/district/{city_id}
GET /v2/district?city={city_id}
Get District by ID
GET /v2/district?id={district_id}
Example Response:
{
"meta": {
"message": "Success Get District",
"code": 200,
"status": "success"
},
"data": [
{
"district_id": "1",
"district_name": "Abiansemal",
"city_id": "17",
"city": "Badung",
"type": "Kabupaten",
"province_id": "1",
"province": "Bali"
}
]
}Get All Subdistricts
GET /v2/subdistrict
Get Subdistricts by City
GET /v2/subdistrict?city={city_id}
Get Subdistrict by District ID
GET /v2/subdistrict/{district_id}
Get Subdistrict by ID
GET /v2/subdistrict?id={subdistrict_id}
Example Response:
{
"meta": {
"message": "Success Get Subdistrict",
"code": 200,
"status": "success"
},
"data": [
{
"subdistrict_id": "1",
"subdistrict_name": "Abiansemal",
"city_id": "17",
"city": "Badung",
"type": "Kabupaten",
"province_id": "1",
"province": "Bali"
}
]
}The API intelligently manages data from two sources:
- Local Database (Primary): Fast response times, no external dependencies
- External API (Fallback): Ensures data completeness when local data is unavailable
All requests are logged with the following information:
- Request method and endpoint
- Data source used (
dborapi) - Response time in milliseconds
- Success/failure status
- Client IP address and User-Agent
- Request payload
{
"meta": {
"message": "Error description",
"code": 500,
"status": "error"
},
"data": []
}200: Success400: Bad Request (Invalid parameters)404: Not Found (Resource not found)500: Internal Server Error
- Database queries: Sub-millisecond response times for local data
- API fallback: Automatic fallback when local data is unavailable
- Caching: Local database acts as a cache for frequently accessed data
- Logging: Minimal performance impact with asynchronous logging
- Clone the repository
- Install dependencies:
composer install - Configure environment variables in
.env - Run migrations:
php artisan migrate - Seed the database (optional):
php artisan db:seed - Start the server:
php artisan serve
RAJAONGKIR_API_KEY=your_rajaongkir_api_key
RAJAONGKIR_API_URL=https://api.rajaongkir.com/starter
API_KEY=your_api_key_for_authentication- Fork the repository
- Create a feature branch
- Commit your changes
- Push to the branch
- Create a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
For support and questions, please contact the development team or create an issue in the repository.