Blockquote
log::warn!("BaseURL: {}",auth_service_base_url); // output: [user_service::repository] BaseURL: "http://auth-app:8000/api/v1/login"
let request_url_test = reqwest::Url::parse(&auth_service_base_url).unwrap(); // error here
log::warn!("Parsed URL: {}", request_url_test.into_string())
Results in following error:
Blockquote
user_app | 2021-06-15 11:53:22,818 WARN [user_service::repository] BaseURL: "http://auth-app:8000/api/v1/login"
user_app | thread 'tokio-runtime-worker' panicked at 'called Result::unwrap() on an Err value: RelativeUrlWithoutBase', src/repository.rs:46:72
What i did try is extending the hostname e.g. auth-app with a domain e.g. auth-app .com
and naming the container explicitly. Parsing did work. Since i want to address an Service this '.com' is really unnecessary and i was wondering why the parse function does not like the described url.
Communication with a docker container over http is no different than communicating with anything else over http. During development, I will often use the command-line curl as a sanity check to make sure I have my docker port mappings, environment variables, etc. set up properly before I assume the error is with my code: Something like
Specific to your instance, if your code is running inside a container that is part of the same swarm/deployment, you should be able to access your service simply via http:://containername:default_port. If it is not running inside the same deployment, you will have to use the ip address/port. Typically I check these with something like
sudo docker container ls | grep "auth-app"
You should see something like 127.0.0.1:ephemeral_port->8080
i would say this proves, that the communication channel between the two containers is working as indended. ( you gave me a hint tho. the url base name was auth-app instead of auth_app )
nonetheless: this didn't change the situation that my URL-String ist not parsed into a URL Object by the Reqwest library via the parse function.
i tried to setup a minimal example:
Blockquote
fn main() {
println!("Hello, world!");
let url = "http://auth_app:8000/api/v1/login";
let parsed_url = reqwest::Url::parse(&url).unwrap();
println!("{}", parsed_url);
}
this did work as expected. And i was wondering why. This led me to inspecting the types. In my appliation i was using 'String' but the parse function expects '&str'. Furthermore i was reading url from an env var.
The env var was enclosed by "" and therefore an invalid url