HttpCallbackSession

Struct HttpCallbackSession 

Source
pub struct HttpCallbackSession { /* private fields */ }
Expand description

A callback-based HTTP session for asynchronous operations

Implementations§

Source§

impl HttpCallbackSession

Source

pub fn new(host: &str, port: u16, token: Option<String>) -> Result<Self, Error>

Create a new callback HTTP session

Examples found in repository?
examples/callback_http.rs (line 10)
8fn main() -> Result<(), Box<dyn std::error::Error>> {
9	// Connect to ReifyDB HTTP server
10	let session = HttpCallbackSession::new("127.0.0.1", 8090, Some("mysecrettoken".to_string()))?;
11
12	// Execute a command to create a table
13	session.command("CREATE NAMESPACE test; CREATE TABLE test.users { id: INT4, name: UTF8 }", None, |result| {
14		match result {
15			Ok(data) => println!("Command executed: {} frames returned", data.frames.len()),
16			Err(e) => println!("Command failed: {}", e),
17		}
18	})?;
19	println!("Command sent");
20
21	// Execute a query
22	session.query("MAP { x: 42, y: 'hello' }", None, |result| {
23		match result {
24			Ok(data) => {
25				println!("Query executed: {} frames returned", data.frames.len());
26				// Print first frame if available
27				if let Some(frame) = data.frames.first() {
28					println!("First frame:\n{}", frame);
29				}
30			}
31			Err(e) => println!("Query failed: {}", e),
32		}
33	})?;
34	println!("Query sent");
35
36	// Wait for callbacks to complete
37	thread::sleep(Duration::from_millis(500));
38
39	Ok(())
40}
Source

pub fn from_client( client: HttpClient, token: Option<String>, ) -> Result<Self, Error>

Create a new callback HTTP session from an existing client

Source

pub fn from_url(url: &str, token: Option<String>) -> Result<Self, Error>

Create from URL (e.g., “http://localhost:8080”)

Source

pub fn with_timeout(self, _timeout: Duration) -> Self

Set timeout for requests

Source

pub fn command<F>( &self, rql: &str, params: Option<Params>, callback: F, ) -> Result<String, Error>
where F: FnOnce(Result<CommandResult, Error>) + Send + 'static,

Send a command with callback

Examples found in repository?
examples/callback_http.rs (lines 13-18)
8fn main() -> Result<(), Box<dyn std::error::Error>> {
9	// Connect to ReifyDB HTTP server
10	let session = HttpCallbackSession::new("127.0.0.1", 8090, Some("mysecrettoken".to_string()))?;
11
12	// Execute a command to create a table
13	session.command("CREATE NAMESPACE test; CREATE TABLE test.users { id: INT4, name: UTF8 }", None, |result| {
14		match result {
15			Ok(data) => println!("Command executed: {} frames returned", data.frames.len()),
16			Err(e) => println!("Command failed: {}", e),
17		}
18	})?;
19	println!("Command sent");
20
21	// Execute a query
22	session.query("MAP { x: 42, y: 'hello' }", None, |result| {
23		match result {
24			Ok(data) => {
25				println!("Query executed: {} frames returned", data.frames.len());
26				// Print first frame if available
27				if let Some(frame) = data.frames.first() {
28					println!("First frame:\n{}", frame);
29				}
30			}
31			Err(e) => println!("Query failed: {}", e),
32		}
33	})?;
34	println!("Query sent");
35
36	// Wait for callbacks to complete
37	thread::sleep(Duration::from_millis(500));
38
39	Ok(())
40}
Source

pub fn query<F>( &self, rql: &str, params: Option<Params>, callback: F, ) -> Result<String, Error>
where F: FnOnce(Result<QueryResult, Error>) + Send + 'static,

Send a query with callback

Examples found in repository?
examples/callback_http.rs (lines 22-33)
8fn main() -> Result<(), Box<dyn std::error::Error>> {
9	// Connect to ReifyDB HTTP server
10	let session = HttpCallbackSession::new("127.0.0.1", 8090, Some("mysecrettoken".to_string()))?;
11
12	// Execute a command to create a table
13	session.command("CREATE NAMESPACE test; CREATE TABLE test.users { id: INT4, name: UTF8 }", None, |result| {
14		match result {
15			Ok(data) => println!("Command executed: {} frames returned", data.frames.len()),
16			Err(e) => println!("Command failed: {}", e),
17		}
18	})?;
19	println!("Command sent");
20
21	// Execute a query
22	session.query("MAP { x: 42, y: 'hello' }", None, |result| {
23		match result {
24			Ok(data) => {
25				println!("Query executed: {} frames returned", data.frames.len());
26				// Print first frame if available
27				if let Some(frame) = data.frames.first() {
28					println!("First frame:\n{}", frame);
29				}
30			}
31			Err(e) => println!("Query failed: {}", e),
32		}
33	})?;
34	println!("Query sent");
35
36	// Wait for callbacks to complete
37	thread::sleep(Duration::from_millis(500));
38
39	Ok(())
40}
Source

pub fn is_authenticated(&self) -> bool

Check if the session is authenticated

Source§

impl HttpCallbackSession

Source

pub fn command_with_handler( &self, rql: &str, params: Option<Params>, handler: impl HttpResponseHandler + 'static, ) -> Result<String, Error>

Execute command with a response handler

Source

pub fn query_with_handler( &self, rql: &str, params: Option<Params>, handler: impl HttpQueryHandler + 'static, ) -> Result<String, Error>

Execute query with a response handler

Trait Implementations§

Source§

impl Drop for HttpCallbackSession

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.