pub struct ClientBuilder { /* private fields */ }Expand description
ClientBuilder provides a series of builder methods to easily construct a Client.
Implementations§
Source§impl ClientBuilder
impl ClientBuilder
Sourcepub fn for_url(url: &str) -> Result<ClientBuilder>
pub fn for_url(url: &str) -> Result<ClientBuilder>
Create a builder for a given URL.
Sourcepub fn method(self, method: String) -> ClientBuilder
pub fn method(self, method: String) -> ClientBuilder
Set the request method used for the initial connection to the SSE endpoint.
Sourcepub fn body(self, body: String) -> ClientBuilder
pub fn body(self, body: String) -> ClientBuilder
Set the request body used for the initial connection to the SSE endpoint.
Sourcepub fn last_event_id(self, last_event_id: String) -> ClientBuilder
pub fn last_event_id(self, last_event_id: String) -> ClientBuilder
Set the last event id for a stream when it is created. If it is set, it will be sent to the server in case it can replay missed events.
Sourcepub fn header(self, name: &str, value: &str) -> Result<ClientBuilder>
pub fn header(self, name: &str, value: &str) -> Result<ClientBuilder>
Set a HTTP header on the SSE request.
Sourcepub fn basic_auth(self, username: &str, password: &str) -> Result<ClientBuilder>
pub fn basic_auth(self, username: &str, password: &str) -> Result<ClientBuilder>
Set the Authorization header with the calculated basic authentication value.
Sourcepub fn reconnect(self, opts: ReconnectOptions) -> ClientBuilder
pub fn reconnect(self, opts: ReconnectOptions) -> ClientBuilder
Configure the client’s reconnect behaviour according to the supplied
ReconnectOptions.
Sourcepub fn redirect_limit(self, limit: u32) -> ClientBuilder
pub fn redirect_limit(self, limit: u32) -> ClientBuilder
Customize the client’s following behavior when served a redirect.
To disable following redirects, pass 0.
By default, the limit is DEFAULT_REDIRECT_LIMIT.
Sourcepub fn build_with_transport<T>(self, transport: T) -> impl Clientwhere
T: HttpTransport,
pub fn build_with_transport<T>(self, transport: T) -> impl Clientwhere
T: HttpTransport,
Build a client with a custom HTTP transport implementation.
§Arguments
transport- An implementation of theHttpTransporttrait that will handle HTTP requests. See theexamples/directory for reference implementations.
§Example
use eventsource_client::ClientBuilder;
let transport = MyTransport::new();
let client = ClientBuilder::for_url("https://live-test-scores.herokuapp.com/scores")
.expect("failed to create client builder")
.build_with_transport(transport);