This repository has been archived by the owner on Jun 26, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Otávio Pace <otaviopp8@gmail.com>
- Loading branch information
Showing
7 changed files
with
68 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
/target | ||
Cargo.lock | ||
datomic-pro-*.jar |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
crux: | ||
docker run -d -p 3000:3000 juxt/crux-standalone:20.02-1.7.0-alpha |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
# Transistor | ||
|
||
A Datomic Client crate. | ||
A Crux Client crate. | ||
* Gave up on datomic already. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
use reqwest::{ | ||
header::{HeaderMap,AUTHORIZATION}, | ||
blocking::{Client}, | ||
Result | ||
}; | ||
|
||
pub struct Crux { | ||
host: String, | ||
port: String, | ||
headers: HeaderMap | ||
} | ||
|
||
impl Crux{ | ||
pub fn new(host: &str, port: &str) -> Self { | ||
Self{host: host.to_string(), port: port.to_string(), headers: HeaderMap::new()} | ||
} | ||
|
||
pub fn with_authorization(mut self, authorization: &str) -> Self { | ||
self.headers.insert(AUTHORIZATION, authorization.parse().unwrap()); | ||
self | ||
} | ||
|
||
fn uri(&self) -> String { | ||
format!("http://{}:{}", self.host, self.port) | ||
} | ||
|
||
pub fn client(&self) -> CruxClient { | ||
CruxClient { | ||
client: reqwest::blocking::Client::new(), | ||
uri: self.uri().clone(), | ||
headers: self.headers.clone() | ||
} | ||
} | ||
} | ||
|
||
pub struct CruxClient { | ||
client: Client, | ||
uri: String, | ||
headers: HeaderMap, | ||
} | ||
|
||
impl CruxClient { | ||
pub fn state(&self) -> Result<String> { | ||
self.client.get(&self.uri) | ||
.headers(self.headers.clone()) | ||
.send()? | ||
.text() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1 @@ | ||
#[cfg(test)] | ||
mod tests { | ||
#[test] | ||
fn it_works() { | ||
assert_eq!(2 + 2, 4); | ||
} | ||
} | ||
pub mod http; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
mod http; | ||
|
||
use http::Crux; | ||
|
||
fn main() { | ||
let body = Crux::new("localhost", "3000").client().state().unwrap(); | ||
|
||
println!("body = {:?}", body); | ||
} |