Mordil
Mordil

Reputation: 128

Empty Body in Vapor Client GET Response

I'm trying to connect to Bamboo HR's API, and I've managed to make this work with curl and Swift Foundation's URLRequest/URLSession (as well as an older Express node.js app).

However, when trying to utilize Vapor's client with the .get() method, I'm getting a successful 200 response from BambooHR - but the response's .body is empty.

Here's the code snippet:

key and {myDomain} are placeholders in the example

let encodedKey = "\(key):x".utf8.base64String
let directoryRootUrl = "https://api.bamboohr.com/api/gateway.php/{myDomain}/v1/employees/directory"

let response = try drop.client.get(
    directoryRootURL,
    headers: [
        "Accept": "application/json",
        "Authorization": "Basic \(encodedKey)",
        "Host": "api.bamboohr.com"
    ])

When I do print(response), this is what's displayed:

Response
- HTTP/1.0 200 OK
- Headers:
    Connection: close
    Vary: User-Agent
    Server: Apache
    Content-Security-Policy:  {...}
    Date: Mon, 16 Jan 2017 00:26:31 GMT
    Content-Type: application/json
    X-Content-Type-Options: nosniff
- Body:

I'm wondering if I'm doing anything wrong with Vapor, or if it's a bug.

Upvotes: 1

Views: 735

Answers (1)

Mordil
Mordil

Reputation: 128

Like tobygriffin suggested, setting:

drop.client = FoundationClient.self

after creating the Droplet worked.

Upvotes: 1

Related Questions