Search code examples
iosswiftrestswift2siesta-swift

Siesta iOS POST request errors out with "unsupported URL"


I am having trouble with Siesta - an iOS REST Client Framework https://bustoutsolutions.github.io/siesta/.

Below is a simple example of a POST request to a REST API server, which fails with a "unsupported URL" error. Does anybody out there have any experience with Siesta and what could be wrong?

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"

Solution

  • 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")