Can only comment on your first question…
Where is the best way to get the different parts of the url?
The platform URL should be available as environment variable C8Y_BASEURL.
See here: “[…]The Cumulocity IoT exposes the REST endpoint /user/currentUser. The microservice retrieves the Cumulocity IoT address from the C8Y_BASEURL
operating system environment variable.”