0

I'm working on RestAPI just to learn how to work with it.

For the testing phase, first I made a login page to get username and password, and trie to connect github with it. I am in early stage of my code, but since it is my first experience, I am faced with this problem.

here is my model (just for logging) and it's not completed yet:

struct LogginReguest {
    var username: String
    var password: String

mutating func gettingAceess() {
    let loginString = "\(self.username):\(self.password)"
    let resurceUrl = "curl -u \(loginString) https://api.github.com"
    guard let loggingUrl = URL(string: resurceUrl) else {fatalError()}

    let logging = URLSession.shared.dataTask(with: loggingUrl)
    logging.resume()
}

}

I use this page for using github API

https://developer.github.com/v3/

The first problem is, in this line::

    guard let loggingUrl = URL(string: resurceUrl) else {fatalError()}

The app crashed and it showed fatalError

It is not recognizing it as the URL. Could you help me on that? And can you tell me how I can read the login error problem from the github server? It would be a great help.

aschultz
  • 1,658
  • 3
  • 20
  • 30
Jon
  • 29
  • 5

1 Answers1

0

you can convert your curl in url

let username = "username"
let password = "password"
let resourceUrl = "https://\(username):\(password)@api.github.com"
guard let loggingUrl = URL(string: resourceUrl) else {fatalError()}

reference: https://stackoverflow.com/a/42833854/3493517

Drugan
  • 144
  • 7