summaryrefslogtreecommitdiff
path: root/game_server/src/backend_connection.rs
diff options
context:
space:
mode:
authorDennis Kobert <d-kobert@web.de>2019-06-11 23:38:13 +0200
committerDennis Kobert <d-kobert@web.de>2019-06-11 23:38:13 +0200
commit2fa4a0e50ebfc97059c8b84dbd17e79f9afc8a8d (patch)
treec3b34ccb2737e347a73768536895cbbaab13cc01 /game_server/src/backend_connection.rs
parentec991104f56e90d7bb2878da2fe6ed4e585dfc46 (diff)
parentaf74efccf8d21e6151022b71f3cacd3fa83024ee (diff)
Merge branch 'rework-backend'
Diffstat (limited to 'game_server/src/backend_connection.rs')
-rw-r--r--game_server/src/backend_connection.rs31
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
+ }
+}