diff --git a/src/event_source.rs b/src/event_source.rs index a18ee1a..0e24e72 100644 --- a/src/event_source.rs +++ b/src/event_source.rs @@ -88,6 +88,28 @@ impl EventSource { Self::new(reqwest::Client::new().get(url)).unwrap() } + /// Create a simple EventSource based on a POST request + pub fn post(url: T, content_type: &str, input: reqwest::Body) -> Self { + Self::new( + reqwest::Client::new() + .post(url) + .body(input) + .header(reqwest::header::CONTENT_TYPE, content_type), + ) + .unwrap() + } + + /// Create a simple EventSource based on a PUT request + pub fn put(url: T, content_type: &str, input: reqwest::Body) -> Self { + Self::new( + reqwest::Client::new() + .put(url) + .body(input) + .header(reqwest::header::CONTENT_TYPE, content_type), + ) + .unwrap() + } + /// Close the EventSource stream and stop trying to reconnect pub fn close(&mut self) { self.is_closed = true;