package javaAPI;
import java.io.IOException;
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.net.http.HttpResponse.BodyHandlers;
import java.util.Scanner;
public class Receita {
public static void main(String[] args) throws IOException, InterruptedException {
Scanner leitura = new Scanner(System.in);
System.out.println("Digite o nome da receita para busca");
var nomeReceita = leitura.nextLine();
String endereco = "https://www.themealdb.com/api/json/v1/1/search.php?s=" + nomeReceita.replace(" ", "+");
HttpClient client = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create(endereco))
.build();
HttpResponse<String> response = client
.send(request, BodyHandlers.ofString());
System.out.println(response.body());
leitura.close();
}
}
package javaAPI;
import java.io.IOException;
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.net.http.HttpResponse.BodyHandlers;
import java.util.Scanner;
public class Criptomoeda {
public static void main(String[] args) throws IOException, InterruptedException {
Scanner leitura = new Scanner(System.in);
System.out.println("Digite a criptomoeda que queira busca exemplo (bitcoin)");
var moeda = leitura.nextLine();
System.out.println("Digite a moeda PARA cotação exemplo (USD)");
var cotacao = leitura.nextLine();
String endereco = "https://api.coingecko.com/api/v3/simple/price?ids=" + moeda + "&vs_currencies=" + cotacao;
HttpClient client = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create(endereco))
.build();
HttpResponse<String> response = client
.send(request, BodyHandlers.ofString());
System.out.println(response.body());
leitura.close();
}
}
package javaAPI;
import java.io.IOException;
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.net.http.HttpResponse.BodyHandlers;
import java.util.Scanner;
public class ConsultaLivro {
public static void main(String[] args) throws IOException, InterruptedException {
Scanner leitura = new Scanner(System.in);
System.out.println("Digite o titulo do livro para busca");
var titulo = leitura.nextLine();
var chave = "AIzaSyDcFu7VrJZncjlhbXuos7-k2GN7J29zQIo";
String endereco = "https://www.googleapis.com/books/v1/volumes?q=" + titulo.replace(" ", "+") + "=epub&key=" + chave;
HttpClient client = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create(endereco))
.build();
HttpResponse<String> response = client
.send(request, BodyHandlers.ofString());
System.out.println(response.body());
leitura.close();
}
}