Get temperature by CEP
-
You need to create your own API key by accessing this URL 🌦️weather API
-
After that, you can use your api_key, and you can put this into the json config below.
-
You can use this API key
dca102b972c84ce989261931242701
if you do not have one, but we do not guarantee if that key is valid at the moment you run the project, so we highly recommend you create your own API key.
-
Execute the command:
make prepare
-
Fill up with your credentials in these files:
env.dev.json
andenv.prod.json
-
We have this JSON example, you must change these variables for
dev
andprod
:{ "temperature" : { "url": "https://api.weatherapi.com", "api_key": "dca102b972c84ce989261931242701" }, "cep": { "url": "https://viacep.com.br" } }
-
Finally, you can run one of these commands:
make run-dev
: to use credentials fromenv.dev.json
make run-prod
: to use credentials fromenv.prod.json
- After you start the application, you can test it.
- We are using the
:8080
port for local/dev environment. - We have this endpoint:
/temperature
inGET
method to get the temperature by CEP, you can use it:${API_URL}/temperature?cep=58070-310
- We have this successfully response:
{ "location": "João Pessoa", "temp_C": 25, "temp_F": 77, "temp_K": 298 }
- You can run the api integration test by running one of these commands in the project root:
- Local:
API_URL=http://localhost:8080 go test -v ./tests/integration
- Production:
API_URL=https://temperature-uz6otgp6yq-uc.a.run.app go test -v ./tests/integration
- Local:
- You can change the local URL, the production URL is the app that is running in the Google Cloud.
- If you need to run all the tests you should execute in the project root:
- Local:
API_URL=http://localhost:8080 go test -v ./...
- Production:
API_URL=https://temperature-uz6otgp6yq-uc.a.run.app go test -v ./...
- Local:
- Set these variables on your favourite shell:
ENV_PROJECT_ID
: This is the projectID that you are using, for example in my case is:generic-316622
ENV_ARG
: this is the environment variable, you can use eitherprod
ordev
.
- You need to log to gcloud using
gcloud auth login
- Then, run
gcloud config set project ${ENV_PROJECT_ID}
- You need to execute
deploy.sh
by running this: (you must changeENV_PROJECT_ID
)ENV_PROJECT_ID=generic-316622 ENV_ARG=prod ./deploy.sh
- For this project, we have this URL to test using
GET
methodcurl https://temperature-uz6otgp6yq-uc.a.run.app/temperature?cep=58070-310 | jq