API Documentation
Complete API reference for Khedut Bazaar location data
Overview
The Khedut Bazaar API provides access to location data including states, districts, and markets scraped from Agriplus.in.
Base URL
https://khedut-bazaar.4born.com/api
Authentication
No authentication required. All endpoints are publicly accessible.
Health Check
GET /api/health
Check API health and get available endpoints
Response:
{
"status": "healthy",
"service": "Khedut Bazaar API",
"version": "1.0.0",
"timestamp": "2024-01-01T12:00:00",
"endpoints": {
"states": "/api/states",
"districts": "/api/states/<state_id>/districts",
"markets": "/api/states/<state_id>/districts/<district_id>/markets",
"stats": "/api/stats"
}
}
Test Endpoint
States
GET /api/states
Get all states with their IDs
Response:
{
"status": "success",
"data": [
{
"id": 1,
"name": "Andaman and Nicobar"
},
{
"id": 2,
"name": "Andhra Pradesh"
}
],
"count": 36,
"timestamp": "2024-01-01T12:00:00"
}
Test Endpoint
Districts
GET /api/states/{state_id}/districts
Get districts for a specific state
Parameters:
state_id
(integer, required) - The ID of the state
Response:
{
"status": "success",
"data": [
{
"id": 130,
"name": "Ahmedabad"
},
{
"id": 131,
"name": "Amreli"
}
],
"count": 33,
"state_id": 11,
"timestamp": "2024-01-01T12:00:00"
}
Test Endpoint
Markets
GET /api/states/{state_id}/districts/{district_id}/markets
Get markets for a specific state and district
Parameters:
state_id
(integer, required) - The ID of the statedistrict_id
(integer, required) - The ID of the district
Response:
{
"status": "success",
"data": [
{
"id": 686,
"name": "Bhavnagar"
},
{
"id": 687,
"name": "Botad"
}
],
"count": 5,
"state_id": 11,
"district_id": 136,
"timestamp": "2024-01-01T12:00:00"
}
Test Endpoint
Markets by District Only
GET /api/districts/{district_id}/markets
Get markets for a specific district (alternative endpoint)
Parameters:
district_id
(integer, required) - The ID of the district
Response:
{
"status": "success",
"data": [
{
"id": 686,
"name": "Bhavnagar"
}
],
"count": 1,
"district_id": 136,
"timestamp": "2024-01-01T12:00:00"
}
Test Endpoint
Statistics
GET /api/stats
Get database statistics
Response:
{
"status": "success",
"data": {
"states": 36,
"districts": 500,
"markets": 2500
},
"timestamp": "2024-01-01T12:00:00"
}
Test Endpoint
Search
GET /api/search?q={query}
Search locations by name
Parameters:
q
(string, required) - Search query
Response:
{
"status": "success",
"data": {
"states": [
{
"id": 11,
"name": "Gujarat"
}
],
"districts": [
{
"id": 130,
"name": "Ahmedabad",
"state_name": "Gujarat"
}
],
"markets": []
},
"query": "gujarat",
"timestamp": "2024-01-01T12:00:00"
}
Test Endpoint
Error Responses
All endpoints return consistent error responses:
400 Bad Request:
{
"status": "error",
"message": "Query parameter 'q' is required",
"timestamp": "2024-01-01T12:00:00"
}
404 Not Found:
{
"status": "error",
"message": "Endpoint not found",
"timestamp": "2024-01-01T12:00:00"
}
500 Internal Server Error:
{
"status": "error",
"message": "Internal server error",
"timestamp": "2024-01-01T12:00:00"
}
Usage Examples
JavaScript/Fetch:
// Get all states
fetch('/api/states')
.then(response => response.json())
.then(data => console.log(data));
// Get districts for Gujarat (ID: 11)
fetch('/api/states/11/districts')
.then(response => response.json())
.then(data => console.log(data));
// Get markets for Ahmedabad district (ID: 130) in Gujarat
fetch('/api/states/11/districts/130/markets')
.then(response => response.json())
.then(data => console.log(data));
cURL:
# Get all states
curl https://khedut-bazaar.4born.com/api/states
# Get districts for Gujarat
curl https://khedut-bazaar.4born.com/api/states/11/districts
# Get markets for Ahmedabad
curl https://khedut-bazaar.4born.com/api/states/11/districts/130/markets