API for States and Cities in Mexico - Readme
This API is designed to provide information about states and cities in Mexico. It is built using Docker and Node.js, making it easy to deploy and scale. Additionally, the infrastructure can be automatically set up on AWS ECS (Elastic Container Service) using Terraform scripts.
Before running the API, ensure you have the following installed:
- Docker: To build and run the containerized Node.js application.
- Node.js: To execute the application locally for development and testing.
- Terraform: To deploy the API to AWS ECS.
-
Clone the repository to your local machine.
-
Navigate to the root folder of the API.
-
Install the Node.js dependencies:
npm install
-
Run the API locally:
npm start
The API will be accessible at
http://localhost:3000
.
-
Make sure you have Docker installed and running.
-
Build the Docker image:
docker build -t mexico-api .
-
Run the Docker container:
docker run -p 3000:3000 -d mexico-api
The API will be accessible at
http://localhost:3000
.
The following steps assume you have an AWS account set up and have the AWS CLI installed with appropriate credentials configured.
-
Navigate to the
terraform
directory in the repository. -
Initialize Terraform:
terraform init
-
Review the deployment plan:
terraform plan -var-file=dev.tfvars -out dev.tfplan
-
Apply the Terraform configuration to create the ECS cluster and deploy the API:
terraform apply dev.tffplan
The API provides the following endpoints: For states:
- GET /state/getAll: Retrieve a list of all states in Mexico.
- GET /state/getByName/:name: Retrieve the details of the specified state.
- POST /state/create: Create a state with the data specified in the body.
- PATCH /state/patch: Patch a state with the data specified in the body.
- PATCH /state/delete/:name: Patch a state with the data specified in the body.
For cities:
- GET /city/getAll: Retrieve a list of all cities in Mexico.
- GET /state/getByName/:name: Retrieve the details of the specified cities.
- POST /state/create: Create a cities with the data specified in the body.
- PATCH /state/patch: Patch a cities with the data specified in the body.
- PATCH /state/delete/:name: Patch a cities with the data specified in the body.
The API returns data in JSON format with the following structure:
[
{
"name": "Distrito Federal",
"code": "MX-DIF",
"subdivision": "federal district"
},
{
"name": "Aguascalientes",
"code": "MX-AGU",
"subdivision": "state"
},
{
"name": "Baja California",
"code": "MX-BCN",
"subdivision": "state"
},
{
"name": "Baja California Sur",
"code": "MX-BCS",
"subdivision": "state"
},
{
"name": "Campeche",
"code": "MX-CAM",
"subdivision": "state"
},
{
"name": "Chiapas",
"code": "MX-CHP",
"subdivision": "state"
},
{
"name": "Chihuahua",
"code": "MX-CHH",
"subdivision": "state"
},
In case of errors, the API returns a JSON response with an appropriate error message and status code.
Contributions to this API are welcome! If you encounter any issues or have suggestions for improvements, feel free to create a pull request or open an issue.