reto10 terminado
This commit is contained in:
10
ejercicios/reto10/Cargo.toml
Normal file
10
ejercicios/reto10/Cargo.toml
Normal file
@@ -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"]}
|
||||||
23
ejercicios/reto10/src/main.rs
Normal file
23
ejercicios/reto10/src/main.rs
Normal file
@@ -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<dyn std::error::Error>> {
|
||||||
|
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(())
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user