Skip to content

Instantly share code, notes, and snippets.

@gabriel-srodrigues
Last active August 29, 2023 00:55
Show Gist options
  • Select an option

  • Save gabriel-srodrigues/7c48ec334c96e8d62dc76975a5d7d1b2 to your computer and use it in GitHub Desktop.

Select an option

Save gabriel-srodrigues/7c48ec334c96e8d62dc76975a5d7d1b2 to your computer and use it in GitHub Desktop.
classe main com unirest
package br.com.digitalhouse.dentistas;
import br.com.digitalhouse.dentistas.dto.DentistaListResponse;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;
import com.mashape.unirest.http.exceptions.UnirestException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@Slf4j
@SpringBootApplication
public class DentistasApplication {
public static void main(String[] args) throws UnirestException, JsonProcessingException {
SpringApplication.run(DentistasApplication.class, args);
log.info("Opa, estou executando uma mensagem depois do inicio da api!!!");
/*
* Iremos consultar a api de dentistas:
* ENDPOINT: https://staging-olimpo-dentistas-backend.bonnasys.com/v1/dentistas
* Usar unirest
*/
HttpResponse<String> response = Unirest
.get("https://staging-olimpo-dentistas-backend.bonnasys.com/v1/dentistas")
.asObject(String.class);
ObjectMapper objectMapper = new ObjectMapper();
DentistaListResponse dentistas = objectMapper
.readValue(response.getBody(), DentistaListResponse.class);
log.info("""
\n STATUS DA REQUISIÇÃO ---------------------------------------
status: %d
status como texto: %s
headers: %s
""".formatted(response.getStatus(), response.getStatusText(), response.getHeaders()));
dentistas.getDentistas().forEach(dentista ->
log.info("""
\n---------------------------------------
Dentista:
id: %d
nome: %s
matricula: %s
""".formatted(dentista.getId(), dentista.getNome(), dentista.getMatricula())));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment