diff options
author | natrixaeria <janng@gmx.de> | 2019-05-15 23:46:11 +0200 |
---|---|---|
committer | natrixaeria <janng@gmx.de> | 2019-05-15 23:46:11 +0200 |
commit | 2f9e5dfaac05538fdf4513569b4df6872ee85b89 (patch) | |
tree | 605a75fb41a09c892a8c8f3af16e984f38e06297 /game_server/src/backend_connection.rs | |
parent | 73eb78e3ac5eb7d382c1aca98da84cd866d54570 (diff) |
Add web client functionality
additionally added -r feature to build.sh, which reverses build
output.
Diffstat (limited to 'game_server/src/backend_connection.rs')
-rw-r--r-- | game_server/src/backend_connection.rs | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/game_server/src/backend_connection.rs b/game_server/src/backend_connection.rs new file mode 100644 index 0000000..9307c4a --- /dev/null +++ b/game_server/src/backend_connection.rs @@ -0,0 +1,31 @@ +use reqwest::{Response, Client, Url, UrlError, Error as ReqError}; + +pub struct BackendConnection { + host: String, + client: Client, + last_response: Option<Result<Response, ReqError>> +} + +impl BackendConnection { + pub fn new(host: &str) -> Self { + BackendConnection { + host: host.to_string(), + client: Client::new(), + last_response: None + } + } + + pub fn request(&mut self, location: &str) -> Result<(), UrlError> { + Ok(self.last_response = + Some(self.client.get(Url::parse(&format!("{}{}", self.host, location))?) + .send())) + } + + pub fn get_response(&self) -> &Option<Result<Response, ReqError>> { + &self.last_response + } + + pub fn host_name<'a>(&'a self) -> &'a str { + &self.host + } +} |