Unresolved import `hyper::Client`

Guys I am here out of desperation because I cannot figure this out for the life of me. I have full imports, did a cargo clean.

[dependencies]
askama = { version = "0.12.1", features = ["with-axum", "markdown"] }
askama_axum = "0.4.0"
async-trait = "0.1.77"
axum = { version = "0.7.3", features = ["macros"] }
axum-login = "0.12.0"
chrono = { version = "0.4.31", features = ["serde"] }
deadpool-redis = { version = "0.14.0", features = ["serde", "rt_async-std_1"] }
dotenv = "0.15.0"
hyper = { version = "1.1.0", features = ["full"] }
lazy_static = "1.4.0"
password-auth = "1.0.0"
rand = "0.8.5"
redis = { version = "0.24.0", features = ["r2d2"] }
regex = "1.10.2"
serde = { version = "1.0.195", features = ["derive"] }
serde_json = "1.0.111"
sqlx = { version = "0.7.3", features = ["postgres", "macros", "time", "chrono", "runtime-tokio-rustls"] }
struct_iterable = "0.1.1"
time = "0.3.31"
tokio = { version = "1.35.1", features = ["full", "time"] }
tower-http = { version = "0.5.0", features = ["cors", "trace", "fs"] }
tower-sessions = { version = "0.9.1", features = ["postgres-store"] }
tracing = "0.1.40"
tracing-subscriber = { version = "0.3.18", features = ["json", "env-filter"] }
validator = { version = "0.16.1", features = ["derive"] }

I do have this which I noted in some other threads but im not so sure...

edition = "2021"

and I am simply just following the GH e.g.

use hyper::Client;

I guess I am just wondering if anyone here might have more ideas in terms of where to look or things to try, because I have already punched every wall in my home already :slight_smile:

Full e.g. - Im just trying to get the import for now.

use std::{net::SocketAddr, collections::HashMap, sync::Arc, env};
use askama::Template;
use ::time::Duration;
use axum::{
    routing::{get, post},
    http::{StatusCode, Request, Uri},
    Json, Router, debug_handler, extract::{Query, State, ConnectInfo}, Extension, response::{IntoResponse, Response}, body::Body,
};
use axum_login::{
    login_required,
    tower_sessions::{ExpiredDeletion, Expiry, SessionManagerLayer, PostgresStore},
    AuthManagerLayerBuilder,
};
use axum::http::{
    header::{ACCEPT, AUTHORIZATION, CONTENT_TYPE},
    HeaderValue, Method,
};
use models::auth::User;
use serde::{Deserialize, Serialize};
use tokio::sync::oneshot;
use crate::{actors::actor::{self, Actor, CreateActor, ActorResponse, ActorHandle, ActorMessage}, error::AppError, models::{self, store::new_db_pool}, users::Backend, web::{protected, auth}};
use sqlx::{postgres::PgPoolOptions, PgPool};
use sqlx::FromRow;
use sqlx::types::time::Date;
use tower_http::{cors::{Any, CorsLayer}, services::ServeDir};
use tower_http::trace::{self, TraceLayer};
use tracing::Level;

// mod errors;
// mod handlers;
// mod infra;
// mod routes;

#[derive(Clone)]
pub struct AppState {
    name: Option<String>,
    actor_handle: ActorHandle,
}

pub struct App {
    pool: PgPool,
}

#[derive(Debug, Template)]
#[template(path = "users.html")]
pub struct UsersTemplate<'a> {
    pub users: &'a Vec<User>,
    pub message: Option<String>,
}

#[derive(Debug, Template)]
#[template(path = "post.html")]
pub struct PostTemplate<'a> {
    pub post_title: &'a str,
    pub post_date: String,
    pub post_body: &'a str,
}

impl App {
    pub async fn new() -> Result<Self, Box<dyn std::error::Error>> {
        dotenv::dotenv().ok();

        // let db_url = env::var("DATABASE_URL").expect("DATABASE_URL not set");
        // let pool = PgPoolOptions::new()
        //     .max_connections(5)
        //     // use your own credentials
        //     .connect(&db_url)
        //     .await
        //     .expect("Unable to connect to DB");
        // sqlx::migrate!().run(&pool).await?;
        let pool = new_db_pool().await?;

        Ok(Self { pool })
    }
        
        // collects the arguments when we run:
        // cargo run --bin markd "A title" ./post.md
        // et args: Vec<String> = env::args().collect();
            
        // // initialize tracing
        // tracing_subscriber::fmt()
        //     .with_target(false)
        //     // .compact()
        //     .json()
        //     .init();
    pub async fn serve(self) -> Result<(), Box<dyn std::error::Error>> {
        // println!("Serve");
        // let cors = CorsLayer::new().allow_origin(Any);

        let cors = CorsLayer::new()
            .allow_origin("http://localhost:3000".parse::<HeaderValue>().unwrap())
            .allow_methods([Method::GET, Method::POST, Method::PATCH, Method::DELETE])
            .allow_credentials(true)
            .allow_headers([AUTHORIZATION, ACCEPT, CONTENT_TYPE]);

        let req = Request::builder()
            .method(Method::POST)
            .uri(Uri::from_static("http://foo.bar"))
            .body(Body::from("a lot of data..."))
            .unwrap();

        let hyper_client = hyper::Client::new();

        tokio::spawn(async move {
            let resp = hyper_client.request(req).await;
        });

        tokio::spawn(async move {
            let http_info = req.extensions().get::<HttpInfo>().unwrap();
        });

Thanks all

There is no Client in hyper v1. There was one in hyper v0.14, but it got removed. There's reqwest::Client, if you want to make http requests.

Edit: Here the gist for the reasoning behind the removal:

The Client still exist in the hyper_util crate. I'd still recommend using reqwest though.

1 Like

Thank you! Something that makes sense. Lesson learned to always check doc version I guess .. now just not really sure how I ended up on the old doc page. Blindly following links I imagine. Thank you again for the quick response, though.

2 Likes