This API endpoint allows you to retrieve, create, update, and delete city information for provinces in Iran.
To access this API, you need to provide a valid JWT token in the request header. Use the token generation page to create a JWT token for authorization.
- Enter valid email address in the provided field and click the "Generate Token" button.
- The PHP script in the background validates the input, checks if the user exists, and generates a JWT token.
- The generated token is displayed in the textarea.
💡 Tip: Access is limited to GET method requests; other methods are accessible for administrators.
Retrieve a list of cities for a specific province by this structure.
- URL:
https://siteyar.net/api/v1//cities?province_id={province_id}
- Method: GET
- Parameters:
province_id
(required): ID of the province for which you want to retrieve cities.page
: Page number for pagination.pagesize
: Number of cities per page.fields
: Comma-separated list of fields to include in the response.orderby
: Field by which the cities should be ordered.
- Headers:
- Key: Authorization
- Value: Bearer [Your JWT Token]
Create a new city.
- URL:
/cities
- Method: POST
- Authorization: Required
- Request Body:
- JSON object representing the new city's data.
Update a city's name.
- URL:
/cities
- Method: PUT
- Authorization: Required
- Request Body:
- JSON object containing
city_id
andname
fields.
- JSON object containing
Delete a city.
- URL:
/cities?city_id={city_id}
- Method: DELETE
- Authorization: Required
- Parameters:
city_id
(required): ID of the city to be deleted.
- Successful responses will have appropriate status codes (e.g., 200 OK, 201 Created).
- Error responses will include a relevant status code along with an error message.
- URL:
https://siteyar.net/api/v1/cities/?province_id=26&page=1&pagesize=3&fields=name,id,province_id&orderby=name%20asc
- Method: GET
- Parameters: :
province_id
: 26,page
: 1,pagesize
: 3,fields
: name,id,province_id,orderby
: name asc - Headers:
- Key: Authorization
- Value: Bearer [Your JWT Token]
{
"http_status": 200,
"http_message": "OK",
"data": [
{
"name": "ازنا",
"id": "371",
"province_id": "26"
},
{
"name": "الشتر",
"id": "374",
"province_id": "26"
},
{
"name": "اليگودرز",
"id": "370",
"province_id": "26"
}
]
}
The CacheUtility class provides functionality for caching API responses to improve performance and reduce server load.
init()
: Initializes cache file address and enables caching for GET requests.cache_exists()
: Checks if a valid cached API response exists.start()
: Starts buffering and serves a cached copy if available.end()
: Caches captured output and sends it to the browser.flush()
: Deletes cached files in the cache directory.
- Cache is enabled when
CACHE_ENABLED
is set to true. - Expiration time: 1 hour (
EXPIRE_TIME = 3600 seconds
).
To use caching:
- Import the
CacheUtility
class. - Use
CacheUtility::start()
before generating API responses. - Call
CacheUtility::end()
after generating responses to save them. - Optionally, use
CacheUtility::flush()
to clear cached files.
Feel free to contribute to this project by submitting pull requests or reporting issues.
This project is licensed under the MIT License - see the LICENSE file for details.
For questions or feedback, please contact .