bouillon 0.2.1

A thin, opinionated wrapper around soup that provides an easy, fluent API for sending HTTP requests.
Documentation
use crate::{Error, IntoUri, Method, Request, RequestBuilder, Response, Result};
use soup::Session;
use soup::prelude::SessionExt as _;

pub trait SessionExt: sealed::SessionExt {
    /// Start building a request to make a `GET` request to a URL.
    fn get<U: IntoUri>(&self, url: U) -> RequestBuilder;
    /// Start building a request to make a `POST` request to a URL.
    fn post<U: IntoUri>(&self, url: U) -> RequestBuilder;
    /// Start building a request to make a `PUT` request to a URL.
    fn put<U: IntoUri>(&self, url: U) -> RequestBuilder;
    /// Start building a request to make a `PATCH` request to a URL.
    fn patch<U: IntoUri>(&self, url: U) -> RequestBuilder;
    /// Start building a request to make a `DELETE` request to a URL.
    fn delete<U: IntoUri>(&self, url: U) -> RequestBuilder;
    /// Start building a request to make a `HEAD` request to a URL.
    fn head<U: IntoUri>(&self, url: U) -> RequestBuilder;
    /// Start building a request to a URL.
    fn request<U: IntoUri>(&self, method: Method, url: U) -> RequestBuilder;
    /// Executes a request.
    fn execute(&self, request: Request) -> impl Future<Output = Result<Response>>;
}

impl sealed::SessionExt for Session {}

impl SessionExt for Session {
    fn get<U: IntoUri>(&self, url: U) -> RequestBuilder {
        self.request(Method::GET, url)
    }

    fn post<U: IntoUri>(&self, url: U) -> RequestBuilder {
        self.request(Method::POST, url)
    }

    fn put<U: IntoUri>(&self, url: U) -> RequestBuilder {
        self.request(Method::PUT, url)
    }

    fn patch<U: IntoUri>(&self, url: U) -> RequestBuilder {
        self.request(Method::PATCH, url)
    }

    fn delete<U: IntoUri>(&self, url: U) -> RequestBuilder {
        self.request(Method::DELETE, url)
    }

    fn head<U: IntoUri>(&self, url: U) -> RequestBuilder {
        self.request(Method::HEAD, url)
    }

    fn request<U: IntoUri>(&self, method: Method, url: U) -> RequestBuilder {
        RequestBuilder::new(self.clone(), method, url.into_uri().map_err(Error::new))
    }

    fn execute(&self, request: Request) -> impl Future<Output = Result<Response>> {
        async {
            let io_priority = request.io_priority();
            let response_body = self
                .send_future(request.message(), io_priority)
                .await
                .map_err(|error| Error::new_with_uri(error, request.message().uri()))?;
            Ok(Response::new(
                request.into_message(),
                response_body,
                io_priority,
            ))
        }
    }
}

mod sealed {
    pub trait SessionExt {}
}