diff --git a/shared/src/codec.rs b/shared/src/codec.rs
index 73d4a64..b0c760e 100644
--- a/shared/src/codec.rs
+++ b/shared/src/codec.rs
@@ -1,83 +1,88 @@
+use leptos::prelude::*;
use leptos::server_fn::codec::{Encoding, FromReq, FromRes, IntoReq, IntoRes};
use leptos::server_fn::request::{ClientReq, Req};
-use leptos::server_fn::response::{ClientRes, Res};
-use leptos::server_fn::error::ServerFnError;
+use leptos::server_fn::response::{ClientRes, Res, TryRes};
+use http::Method;
+use bytes::Bytes;
use serde::{de::DeserializeOwned, Serialize};
use std::future::Future;
pub struct MessagePack;
-impl leptos::server_fn::codec::ContentType for MessagePack {
+impl leptos::server_fn::ContentType for MessagePack {
const CONTENT_TYPE: &'static str = "application/msgpack";
}
impl Encoding for MessagePack {
- const METHOD: leptos::server_fn::request::Method = leptos::server_fn::request::Method::POST;
+ const METHOD: Method = Method::POST;
}
#[cfg(any(feature = "ssr", feature = "hydrate"))]
-impl IntoReq for MessagePack
+impl IntoReq for T
where
- Input: Serialize + Send,
- Output: Send,
+ Request: ClientReq,
+ T: Serialize + Send,
+ Error: Send,
{
- fn into_req(self, args: Input, path: &str) -> Result {
- let data = rmp_serde::to_vec(&args)
- .map_err(|e| ServerFnError::Serialization(e.to_string()))?;
-
- ClientReq::try_new(
- leptos::server_fn::request::Method::POST,
+ fn into_req(self, path: &str, accepts: &str) -> Result {
+ let data = rmp_serde::to_vec(&self)
+ .map_err(|e| ServerFnError::new(e.to_string()).into())?;
+
+ // Use try_new_post_bytes which should be available on ClientReq trait
+ Request::try_new_post_bytes(
path,
- leptos::server_fn::request::Payload::Binary(bytes::Bytes::from(data))
+ MessagePack::CONTENT_TYPE,
+ accepts,
+ Bytes::from(data)
)
}
}
#[cfg(any(feature = "ssr", feature = "hydrate"))]
-impl FromRes for MessagePack
+impl FromRes for T
where
- Input: Send,
- Output: DeserializeOwned + Send,
+ Response: ClientRes + Send,
+ T: DeserializeOwned + Send,
+ Error: Send,
{
- fn from_res(res: ClientRes) -> impl Future