Incorrect URL Formation for API Request with Multi-Word Artist Names

I am working on an iOS application in Swift that fetches song lyrics using a REST API. However, I am facing an issue with constructing the correct URL when the artist or title names contain multiple words.

Problem:
When the artist name contains spaces (e.g., "Burna Boy"), the URL does not format correctly, leading to a malformed request. The desired format is like https://api.example.com/v1/Burna%20Boy/City%20Boys, but my function generates https://api.example.com/v1/Burna%20Boy%20City%20Boys.

Code:
Here is the Swift function I use to fetch the lyrics:

func fetchLyrics(artist: String, title: String) async throws -> String {
    let fullPath = "\(artist)/\(title)"
    let encodedPath = fullPath.addingPercentEncoding(withAllowedCharacters: .urlPathAllowed) ?? ""
    let endpoint = "\(baseURL)/\(encodedPath)"
    print("---->", endpoint)
    guard let url = URL(string: endpoint) else {
        throw NetworkError.invalidURL
    }

    var request = URLRequest(url: url)
    request.httpMethod = "GET"

    do {
        let (data, response) = try await session.data(for: request)

        guard let httpResponse = response as? HTTPURLResponse, httpResponse.statusCode == 200 else {
            throw NetworkError.invalidResponse
        }

        do {
            let lyricsResponse = try JSONDecoder().decode(LyricsResponse.self, from: data)
            return lyricsResponse.lyrics
        } catch {
              throw NetworkError.decodingFailed
        }
    } catch {
        throw NetworkError.requestFailed
    }
}

Expected URL Example:
https://api.example.com/v1/Burna%20Boy/City%20Boys

Actual Output:
https://api.example.com/v1/Burna%20Boy%20City%20Boys

Question:
How can I modify my function to correctly encode the URL path while preserving the necessary structure for the API (i.e., keeping the slash between the artist and the song title and encoding spaces as %20)?

Additional Information:
I am using Swift 5 and URLSession for network requests. The baseURL in my function is correct and ends with /v1.

Attempts:
I tried adjusting the addingPercentEncoding parameters and concatenation sequence, but the issue persists with multi-word artists and titles.

Any suggestions or corrections to my approach would be greatly appreciated!

Your function appears to work on my machine...

import Network
import Foundation

let baseURL = "example.com"

func fetchLyrics(artist: String, title: String) -> String {
	let fullPath = "\(artist)/\(title)"
	let encodedPath = fullPath.addingPercentEncoding(withAllowedCharacters: .urlPathAllowed) ?? ""
	let endpoint = "\(baseURL)/\(encodedPath)"
	print("---->", endpoint)
	guard let url = URL(string: endpoint) else {
		print("Error making URL from \(endpoint)" )
		return "BAD"
	}
	return url.description
}

print(fetchLyrics(artist: "Two words", title: "Also Multiple Words"))

Gives:

----> example.com/Two%20words/Also%20Multiple%20Words
example.com/Two%20words/Also%20Multiple%20Words

Thats the wrong base url you are using. Use this lyrics.ovh ยท Apiary