This Symfony-based API provides endpoints for querying various postal codes in Spain.
The Spanish Postal Codes API is built using Symfony, offering a simple and efficient way to retrieve information about postal codes across different regions of Spain. It allows users to query the API to obtain details such as provinces, towns, and postal codes associated with specific locations within Spain.
-
/api/locations
: Retrieve information about all locations in Spain.- Method: GET
- Response: JSON array containing details of all locations.
-
/api/locations/{codPostal}
: Retrieve information about locations in Spain based on the provided postal code.- Method: GET
- Parameters:
{codPostal}
: The postal code to search for.
- Response: JSON array containing details of all locations matching the provided postal code.
To use the Spanish Postal Codes API, you can send HTTP requests to the provided endpoints using any HTTP client or web browser. Below are some examples of how you can interact with the API:
Send a GET request to /api/locations
endpoint to retrieve information about all locations in Spain.
Example using cURL:
curl -X GET http://your-api-domain.com/api/locations
...
Send a GET request to /api/locations/{codPostal}
endpoint, replacing {codPostal}
with the desired postal code, to retrieve information about locations in Spain based on the provided postal code.
Example using cURL:
curl -X GET http://your-api-domain.com/api/locations/28001
Data files in CSV format are available in the data
folder.
To install and run the Spanish Postal Codes API on your local machine or server, follow these steps:
-
Clone the repository:
git clone https://github.com/codecruz/spain-postal-codes.git
-
Install dependencies using Composer:
composer install
-
Configure your database connection in the
.env
file. -
Create the database schema:
php bin/console doctrine:database:create
php bin/console doctrine:schema:update --force
-
Start the Symfony server:
php bin/console server:start
-
You can now access the API at
http://localhost:8000
.
Contributions to the Spanish Postal Codes API are welcome! If you'd like to contribute, please follow these steps:
-
Fork the repository.
-
Create a new branch for your feature or bug fix.
This project is licensed under the MIT License. You are free to use, modify, and distribute this software as permitted by the license. See the LICENSE
file for more details.
If you find any missing data in the file es_cp.csv, I would appreciate any contributions and pull requests.
If this project or the information within it has been helpful to you, please give it a star (⭐)!
Thank you for your support!