Trait IntoReq

pub trait IntoReq<Encoding, Request, E> {
    // Required method
    fn into_req(self, path: &str, accepts: &str) -> Result<Request, E>;
}
Expand description

Serializes a data type into an HTTP request, on the client.

Implementations use the methods of the ClientReq trait to convert data into a request body. They are often quite short, usually consisting of just two steps:

  1. Serializing the data into some String, Bytes, or Stream.
  2. Creating a request with a body of that type.

For example, here’s the implementation for Json.

ⓘ
impl<E, T, Request> IntoReq<Json, Request, E> for T
where
    Request: ClientReq<E>,
    T: Serialize + Send,
{
    fn into_req(
        self,
        path: &str,
        accepts: &str,
    ) -> Result<Request, E> {
        // try to serialize the data
        let data = serde_json::to_string(&self)
            .map_err(|e| ServerFnErrorErr::Serialization(e.to_string()).into_app_error())?;
        // and use it as the body of a POST request
        Request::try_new_post(path, accepts, Json::CONTENT_TYPE, data)
    }
}

Required Methods§

fn into_req(self, path: &str, accepts: &str) -> Result<Request, E>

Attempts to serialize the arguments into an HTTP request.

Implementors§

§

impl<E, T, Encoding, Request> IntoReq<Patch<Encoding>, Request, E> for T
where Request: ClientReq<E>, Encoding: Encodes<T>, E: FromServerFnError,

§

impl<E, T, Encoding, Request> IntoReq<Post<Encoding>, Request, E> for T
where Request: ClientReq<E>, Encoding: Encodes<T>, E: FromServerFnError,

§

impl<E, T, Encoding, Request> IntoReq<Put<Encoding>, Request, E> for T
where Request: ClientReq<E>, Encoding: Encodes<T>, E: FromServerFnError,

§

impl<E, T, Request> IntoReq<DeleteUrl, Request, E> for T
where Request: ClientReq<E>, T: Serialize + Send, E: FromServerFnError,

§

impl<E, T, Request> IntoReq<GetUrl, Request, E> for T
where Request: ClientReq<E>, T: Serialize + Send, E: FromServerFnError,

§

impl<E, T, Request> IntoReq<PatchUrl, Request, E> for T
where Request: ClientReq<E>, T: Serialize + Send, E: FromServerFnError,

§

impl<E, T, Request> IntoReq<PostUrl, Request, E> for T
where Request: ClientReq<E>, T: Serialize + Send, E: FromServerFnError,

§

impl<E, T, Request> IntoReq<PutUrl, Request, E> for T
where Request: ClientReq<E>, T: Serialize + Send, E: FromServerFnError,

§

impl<E, T, Request> IntoReq<Streaming, Request, E> for T
where Request: ClientReq<E>, T: Stream<Item = Bytes> + Send + 'static, E: FromServerFnError,

§

impl<E, T, Request> IntoReq<StreamingText, Request, E> for T
where Request: ClientReq<E>, T: Into<TextStream<E>>, E: FromServerFnError,