bustoutsolutions / siesta

The civilized way to write REST API clients for iOS / macOS
https://bustoutsolutions.github.io/siesta/
MIT License
2.19k stars 157 forks source link

Unsupported URL error? #8

Closed Rhuantavan closed 8 years ago

Rhuantavan commented 8 years ago

Over at SO I have posted a question about siesta erroring-out on a simple post request: http://stackoverflow.com/questions/33147850/siesta-ios-post-request-errors-out-with-unsupported-url

Unfortunately I cannot create a new "siesta-swift" since I haven't got enough reputation to create a new tag.

Siesta configuration & login server call

let api = Service(base: "http://myapidomain.net/rest")

enabledLogCategories = LogCategory.all

let parameters = ["username": "username", "password": "password"]

api.resource(url: "users/login").request(.POST, json: NSDictionary(dictionary: parameters)).success { data in
    debugPrint("success logging in")
}.failure { error in
    debugPrint("failed to log in")
}

Debug log

[Siesta:Configuration] Computing configuration for Siesta.Resource(users/login)[]
[Siesta:Configuration] Applying config 0 [Siesta default response transformers] to Siesta.Resource(users/login)[]
[Siesta:NetworkDetails] Request: 
    headers: (1)
      Content-Type: application/json
[Siesta:Network] POST users/login
[Siesta:Network] – ← POST users/login
[Siesta:NetworkDetails] Raw response headers: –
[Siesta:NetworkDetails] Raw response body: 0 bytes
[Siesta:NetworkDetails] Response after transformer pipeline:  (new data) 
   Failure
     userMessage:    "unsupported URL"
     nsError:        "unsupported URL"
"failed to log in"
pcantrell commented 8 years ago

That's a good heads up about tagging requiring reputation on Stack Overflow. Hand’t even occurred to me! Perhaps I'll rethink that recommendation about getting help in the README.

The Service.resource(url:) method — the one with the parameter labeled url: — expects a complete URL. It looks like you want Service.resource(_:), which takes a path relative to the Service’s base URL.

Try:

api.resource("users/login")
Rhuantavan commented 8 years ago

Yes, the resource(url:) was the problem. Thanks.

pcantrell commented 8 years ago

Sure thing!

On Oct 15, 2015, at 9:50 AM, Rhuantavan notifications@github.com wrote:

Yes, the resource(url:) was the problem. Thanks.

— Reply to this email directly or view it on GitHub https://github.com/bustoutsolutions/siesta/issues/8#issuecomment-148409513.