0% found this document useful (0 votes)
49 views1 page

Java API Request Example Code

Uploaded by

dalmagro599
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
49 views1 page

Java API Request Example Code

Uploaded by

dalmagro599
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

---------- FAZER REQUISIÇÃO API EM JAVA ----------

public class Main {


public static void main(String[] args) {
ConsumoApi api = new ConsumoApi();
String url = "[Link]
String dados = [Link](url);
[Link](dados);
}
}

public class ConsumoApi {


public String obterDados(String endereco) {
HttpClient client = [Link]();
HttpRequest request = [Link]()
.uri([Link](endereco))
.build();
HttpResponse<String> response = null;
try {
response = client
.send(request, [Link]());
} catch (IOException e) {
throw new RuntimeException(e);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}

String json = [Link]();


return json;
}
}

You might also like