pub struct CommandRequest {
pub headers: Vec<(String, String)>,
pub body: Option<Vec<u8>>,
pub content_type: Option<String>,
pub content_schema: Option<String>,
}Expand description
A command request to execute a state change.
Fields§
§headers: Vec<(String, String)>HTTP-style headers for the request.
body: Option<Vec<u8>>Optional request body.
content_type: Option<String>Content type of the body (e.g., “application/json”).
content_schema: Option<String>Optional content schema URL for validation.
Implementations§
Source§impl CommandRequest
impl CommandRequest
Sourcepub fn new() -> CommandRequest
pub fn new() -> CommandRequest
Create a new empty command request.
Sourcepub fn with_body(body: Vec<u8>) -> CommandRequest
pub fn with_body(body: Vec<u8>) -> CommandRequest
Create a command request with a body.
Sourcepub fn json<T>(value: &T) -> Result<CommandRequest, CommandRequestError>where
T: Serialize,
pub fn json<T>(value: &T) -> Result<CommandRequest, CommandRequestError>where
T: Serialize,
Create a command request with a JSON-serialized body.
This serializes the value to JSON and sets the appropriate Content-Type header.
§Example
use evidentsource_core::domain::CommandRequest;
use serde::Serialize;
#[derive(Serialize)]
struct CreateAccount {
account_id: String,
initial_balance: u64,
}
let cmd = CreateAccount {
account_id: "acc-123".to_string(),
initial_balance: 1000,
};
let request = CommandRequest::json(&cmd).unwrap();
assert_eq!(request.get_header("Content-Type"), Some("application/json"));Sourcepub fn header(
self,
name: impl Into<String>,
value: impl Into<String>,
) -> CommandRequest
pub fn header( self, name: impl Into<String>, value: impl Into<String>, ) -> CommandRequest
Add a header to the request.
Sourcepub fn body(self, body: Vec<u8>) -> CommandRequest
pub fn body(self, body: Vec<u8>) -> CommandRequest
Set the request body.
Sourcepub fn content_type(self, content_type: impl Into<String>) -> CommandRequest
pub fn content_type(self, content_type: impl Into<String>) -> CommandRequest
Set the content type.
§Example
use evidentsource_core::domain::CommandRequest;
let request = CommandRequest::new()
.body(b"<xml>data</xml>".to_vec())
.content_type("application/xml");Sourcepub fn content_schema(self, schema_url: impl Into<String>) -> CommandRequest
pub fn content_schema(self, schema_url: impl Into<String>) -> CommandRequest
Set the content schema URL.
§Example
use evidentsource_core::domain::CommandRequest;
let request = CommandRequest::new()
.body(b"{}".to_vec())
.content_type("application/json")
.content_schema("https://example.com/schemas/command.json");Sourcepub fn get_header(&self, name: &str) -> Option<&str>
pub fn get_header(&self, name: &str) -> Option<&str>
Get a header value by name.
Trait Implementations§
Source§impl Clone for CommandRequest
impl Clone for CommandRequest
Source§fn clone(&self) -> CommandRequest
fn clone(&self) -> CommandRequest
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for CommandRequest
impl Debug for CommandRequest
Source§impl Default for CommandRequest
impl Default for CommandRequest
Source§fn default() -> CommandRequest
fn default() -> CommandRequest
Returns the “default value” for a type. Read more
Auto Trait Implementations§
impl Freeze for CommandRequest
impl RefUnwindSafe for CommandRequest
impl Send for CommandRequest
impl Sync for CommandRequest
impl Unpin for CommandRequest
impl UnwindSafe for CommandRequest
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
Wrap the input message
T in a tonic::Request