pub struct HttpCallbackSession { /* private fields */ }Expand description
A callback-based HTTP session for asynchronous operations
Implementations§
Source§impl HttpCallbackSession
impl HttpCallbackSession
Sourcepub fn new(host: &str, port: u16, token: Option<String>) -> Result<Self, Error>
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}Sourcepub fn from_client(
client: HttpClient,
token: Option<String>,
) -> Result<Self, Error>
pub fn from_client( client: HttpClient, token: Option<String>, ) -> Result<Self, Error>
Create a new callback HTTP session from an existing client
Sourcepub fn from_url(url: &str, token: Option<String>) -> Result<Self, Error>
pub fn from_url(url: &str, token: Option<String>) -> Result<Self, Error>
Create from URL (e.g., “http://localhost:8080”)
Sourcepub fn with_timeout(self, _timeout: Duration) -> Self
pub fn with_timeout(self, _timeout: Duration) -> Self
Set timeout for requests
Sourcepub fn command<F>(
&self,
rql: &str,
params: Option<Params>,
callback: F,
) -> Result<String, Error>
pub fn command<F>( &self, rql: &str, params: Option<Params>, callback: F, ) -> Result<String, Error>
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}Sourcepub fn query<F>(
&self,
rql: &str,
params: Option<Params>,
callback: F,
) -> Result<String, Error>
pub fn query<F>( &self, rql: &str, params: Option<Params>, callback: F, ) -> Result<String, Error>
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}Sourcepub fn is_authenticated(&self) -> bool
pub fn is_authenticated(&self) -> bool
Check if the session is authenticated
Trait Implementations§
Auto Trait Implementations§
impl Freeze for HttpCallbackSession
impl RefUnwindSafe for HttpCallbackSession
impl Send for HttpCallbackSession
impl Sync for HttpCallbackSession
impl Unpin for HttpCallbackSession
impl UnwindSafe for HttpCallbackSession
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