Distributed Trace & Span
- 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
3a8c1f1cf26f457394342515242702
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
. - We have this JSON example, you must change the
temperature.api_key
with your weather API key credentials in the file:env.json
.
{
"service_a": {
"port": "8085"
},
"service_b": {
"port": "50055",
"host": "service_b:50055"
},
"temperature" : {
"url": "https://api.weatherapi.com",
"api_key": "3a8c1f1cf26f457394342515242702"
},
"cep": {
"url": "https://viacep.com.br"
},
"zipkin": {
"host": "zipkin_svc:9411",
"endpoint": "http://zipkin_svc:9411/api/v2/spans"
}
}
- Finally, you can run the command
make run
.
- After you start the application, you can test it.
- We are using the
:8080
port. - We have this endpoint:
/temperature
inPOST
method to get the temperature by CEP, you can use it in localhost:- ✅
200 response
curl -i -X POST http://127.0.0.1:8080/temperature -d '{"cep":"64075525"}'
HTTP/1.1 200 OK Content-Type: application/json Date: Wed, 28 Feb 2024 04:27:39 GMT Content-Length: 56 {"city":"Teresina","temp_C":25,"temp_F":77,"temp_K":298}
- ❌
422 response
curl -i -X POST http://127.0.0.1:8080/temperature -d '{"cep":"012345"}'
HTTP/1.1 422 Unprocessable Entity Content-Type: text/plain; charset=utf-8 X-Content-Type-Options: nosniff Date: Wed, 28 Feb 2024 04:29:17 GMT Content-Length: 16 invalid zipcode
- ❌
404 response
curl -i -X POST http://127.0.0.1:8080/temperature -d '{"cep":"00001033"}'
HTTP/1.1 404 Not Found Content-Type: text/plain; charset=utf-8 X-Content-Type-Options: nosniff Date: Wed, 28 Feb 2024 04:31:00 GMT Content-Length: 22 can not found zipcode
- ✅