pub struct Http<InputProtocol, OutputProtocol>(/* private fields */);Expand description
The http protocol with specific input and output encodings for the request and response. This is the default protocol server functions use if no override is set in the server function macro
The http protocol accepts two generic argument that define how the input and output for a server
function are turned into HTTP requests and responses. For example, Http<GetUrl, Json> will
accept a Url encoded Get request and return a JSON post response.
§Example
use serde::{Serialize, Deserialize};
use server_fn::{Http, ServerFnError, codec::{Json, GetUrl}};
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Message {
user: String,
message: String,
}
// The http protocol can be used on any server function that accepts and returns arguments that implement
// the [`IntoReq`] and [`FromRes`] traits.
//
// In this case, the input and output encodings are [`GetUrl`] and [`Json`], respectively which requires
// the items to implement [`IntoReq<GetUrl, ...>`] and [`FromRes<Json, ...>`]. Both of those implementations
// require the items to implement [`Serialize`] and [`Deserialize`].
#[server(protocol = Http<GetUrl, Json>)]
async fn echo_http(
input: Message,
) -> Result<Message, ServerFnError> {
Ok(input)
}Trait Implementations§
Source§impl<InputProtocol, OutputProtocol, Input, Output, Client, Server, E> Protocol<Input, Output, Client, Server, E> for Http<InputProtocol, OutputProtocol>where
Input: IntoReq<InputProtocol, <Client as Client<E>>::Request, E> + FromReq<InputProtocol, <Server as Server<E>>::Request, E> + Send,
Output: IntoRes<OutputProtocol, <Server as Server<E>>::Response, E> + FromRes<OutputProtocol, <Client as Client<E>>::Response, E> + Send,
E: FromServerFnError,
InputProtocol: Encoding,
OutputProtocol: Encoding,
Client: Client<E>,
Server: Server<E>,
impl<InputProtocol, OutputProtocol, Input, Output, Client, Server, E> Protocol<Input, Output, Client, Server, E> for Http<InputProtocol, OutputProtocol>where
Input: IntoReq<InputProtocol, <Client as Client<E>>::Request, E> + FromReq<InputProtocol, <Server as Server<E>>::Request, E> + Send,
Output: IntoRes<OutputProtocol, <Server as Server<E>>::Response, E> + FromRes<OutputProtocol, <Client as Client<E>>::Response, E> + Send,
E: FromServerFnError,
InputProtocol: Encoding,
OutputProtocol: Encoding,
Client: Client<E>,
Server: Server<E>,
Auto Trait Implementations§
impl<InputProtocol, OutputProtocol> Freeze for Http<InputProtocol, OutputProtocol>
impl<InputProtocol, OutputProtocol> RefUnwindSafe for Http<InputProtocol, OutputProtocol>where
InputProtocol: RefUnwindSafe,
OutputProtocol: RefUnwindSafe,
impl<InputProtocol, OutputProtocol> Send for Http<InputProtocol, OutputProtocol>
impl<InputProtocol, OutputProtocol> Sync for Http<InputProtocol, OutputProtocol>
impl<InputProtocol, OutputProtocol> Unpin for Http<InputProtocol, OutputProtocol>
impl<InputProtocol, OutputProtocol> UnwindSafe for Http<InputProtocol, OutputProtocol>where
InputProtocol: UnwindSafe,
OutputProtocol: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> SerializableKey for T
impl<T> SerializableKey for T
Source§impl<T> StorageAccess<T> for T
impl<T> StorageAccess<T> for T
Source§fn as_borrowed(&self) -> &T
fn as_borrowed(&self) -> &T
Borrows the value.
Source§fn into_taken(self) -> T
fn into_taken(self) -> T
Takes the value.