From 117cc877833eeba9d8a2541f50462e22a2f00333 Mon Sep 17 00:00:00 2001 From: Manuel Riquelme Date: Fri, 23 Jun 2023 17:31:56 +0200 Subject: [PATCH] reto10 terminado --- ejercicios/reto10/Cargo.toml | 10 ++++++++++ ejercicios/reto10/src/main.rs | 23 +++++++++++++++++++++++ 2 files changed, 33 insertions(+) create mode 100644 ejercicios/reto10/Cargo.toml create mode 100644 ejercicios/reto10/src/main.rs diff --git a/ejercicios/reto10/Cargo.toml b/ejercicios/reto10/Cargo.toml new file mode 100644 index 0000000..cbf92cd --- /dev/null +++ b/ejercicios/reto10/Cargo.toml @@ -0,0 +1,10 @@ +[package] +name = "reto10" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +reqwest = "0.11.12" +tokio = {version = "1", features = ["full"]} diff --git a/ejercicios/reto10/src/main.rs b/ejercicios/reto10/src/main.rs new file mode 100644 index 0000000..66f58b9 --- /dev/null +++ b/ejercicios/reto10/src/main.rs @@ -0,0 +1,23 @@ +/* + * Llamar a una API es una de las tareas más comunes en programación. + * + * Implementa una llamada HTTP a una API (la que tú quieras) y muestra su + * resultado a través de la terminal. Por ejemplo: Pokémon, Marvel... + * + * Aquí tienes un listado de posibles APIs: + * https://github.com/public-apis/public-apis + */ + +#[tokio::main] +async fn main() -> Result<(), Box> { + let html: String = reqwest::get("https://bible-api.com/john%203:16") // Se pasa el url o endpoint con el cual se interacturara + .await? // Hace que reqwest espere por la respuesta del servidor + .text() //Convierte el resultado en un String + .await?; + // println!("{:?}", html); + let texto = html.as_str(); + let vector: Vec<&str> = texto.split(":").collect(); + println!("{}", vector[8]); + + Ok(()) +}