Sample code for 30+ languages & platforms
Swift

Send a Bodyless REST Request into a StringBuilder

See more REST Examples

Demonstrates Rest.FullRequestNoBodySb, which sends a request with no body and stores the text response body in a StringBuilder.

Background. This variant of the no-body full request writes the response into a StringBuilder rather than returning it as a string, which is convenient when the response will be further processed in place.

Chilkat Swift Downloads

Swift

func chilkatTest() {
    var success: Bool = false

    let rest = CkoRest()!
    var bTls: Bool = true
    var bAutoReconnect: Bool = true
    success = rest.connect(hostname: "example.com", port: 443, tls: bTls, autoReconnect: bAutoReconnect)
    if success == false {
        print("\(rest.lastErrorText!)")
        return
    }

    //  FullRequestNoBodySb sends a request with no body and stores the text response body in a
    //  StringBuilder.
    let sbResponse = CkoStringBuilder()!
    success = rest.fullRequestNoBodySb(httpVerb: "GET", uriPath: "/api/items/123", sb: sbResponse)
    if success == false {
        print("\(rest.lastErrorText!)")
        return
    }

    var responseText: String? = sbResponse.getAsString()
    if sbResponse.lastMethodSuccess == false {
        print("\(sbResponse.lastErrorText!)")
        return
    }

    print("\(responseText!)")

}