forester_http/api.rs
1/// The api to Forester instance of http server
2/// It is used to get access to the blackboard and to trace events.
3///
4/// #Example
5/// ```rust
6/// use forester_http::api::ForesterHttpApi;
7///
8/// async fn main() {
9/// let api = ForesterHttpApi::new("http://localhost:10000".to_string());
10/// let _ = reqwest::get(api.print_trace()).await;
11/// }
12///
13/// ```
14pub struct ForesterHttpApi {
15 /// The base url of the Forester instance. Typically it is http://localhost:10000
16 pub base: String,
17}
18
19impl ForesterHttpApi {
20 /// creates a new trace event
21 pub fn trace_event(&self) -> String {
22 format!("{}/tracer/custom", self.base)
23 }
24 /// prints the trace or if the file is big the tail of the trace (last 100 lines)
25 pub fn print_trace(&self) -> String {
26 format!("{}/tracer/print", self.base)
27 }
28 /// lock the key in the blackboard
29 pub fn lock(&self, key: String) -> String {
30 format!("{}/bb/{key}/lock", self.base)
31 }
32 /// unlock the key in the blackboard
33 pub fn unlock(&self, key: String) -> String {
34 format!("{}/bb/{key}/unlock", self.base)
35 }
36 /// check if the key is locked in the blackboard
37 pub fn locked(&self, key: String) -> String {
38 format!("{}/bb/{key}/locked", self.base)
39 }
40 /// check if the key is in the blackboard
41 pub fn contains(&self, key: String) -> String {
42 format!("{}/bb/{key}/contains", self.base)
43 }
44 /// take the key from the blackboard.
45 pub fn take(&self, key: String) -> String {
46 format!("{}/bb/{key}/take", self.base)
47 }
48 /// get the key from the blackboard.
49 pub fn get(&self, key: String) -> String {
50 format!("{}/bb/{key}", self.base)
51 }
52 /// put the key to the blackboard.
53 pub fn put(&self, key: String) -> String {
54 format!("{}/bb/{key}", self.base)
55 }
56 pub fn new(base: String) -> Self {
57 Self { base }
58 }
59}