1
resposta

[Sugestão] 3. Consulta à API do TheMealDB

import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.util.Scanner;

public class TheMealDbApiExemplo {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        System.out.println("Digite o nome da receita:");
        String nomeReceita = scanner.nextLine();

        String apiUrl = "https://www.themealdb.com/api/json/v1/1/search.php?s=" + nomeReceita.replace(" ", "+");

        HttpClient client = HttpClient.newHttpClient();
        HttpRequest request = HttpRequest.newBuilder()
                .uri(URI.create(apiUrl))
                .build();

        try {
            HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
            System.out.println("Resposta da API: " + response.body());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
1 resposta

Interessante como vc fez! valeu por compartilhar...