When writing API clients, what is considered the proper way of concatenating a URL together with multiple endpoints?
For example with the Blizzard API:
WowEndpoints := [...]string{"achievements", "realm"}
Bliz := &Blizzard{
Url: "https://us.api.battle.net/wow",
Params: ReqParams,
Client: BClient,
Endpoints: WowEndpoints,
}
// build the realm status request.
req, err := http.NewRequest("GET", fmt.Sprintf("%s/%s/status", Bliz.Url, Bliz.Endpoints[1]), nil)
If you look at Bliz.Url
, there is no trailing slash in the top-level URL. Normally, I just add the slashes when formatting API endpoints as if it was a folder structure, as you can see when I do the fmt.Sprintf
operation.
I'm not sure where I picked up this habit, but I wanted to see if there was a recommended or preferred way of building URL endpoints for APIs.