From 2f9e5dfaac05538fdf4513569b4df6872ee85b89 Mon Sep 17 00:00:00 2001 From: natrixaeria Date: Wed, 15 May 2019 23:46:11 +0200 Subject: Add web client functionality additionally added -r feature to build.sh, which reverses build output. --- game_server/src/backend_connection.rs | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 game_server/src/backend_connection.rs (limited to 'game_server/src/backend_connection.rs') 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> +} + +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> { + &self.last_response + } + + pub fn host_name<'a>(&'a self) -> &'a str { + &self.host + } +} -- cgit v1.2.3-54-g00ecf