Sample code for 30+ languages & platforms
Go

Send a REST Request using StringBuilder Bodies

See more REST Examples

Demonstrates Rest.FullRequestSb, which sends a complete request whose text body is read from a StringBuilder and stores the text response body in a second StringBuilder.

Background. Using StringBuilder objects for the request and response bodies avoids extra string conversions, which is helpful when working with large payloads.

Chilkat Go Downloads

Go
    success := false

    rest := chilkat.NewRest()
    bTls := true
    bAutoReconnect := true
    success = rest.Connect("example.com",443,bTls,bAutoReconnect)
    if success == false {
        fmt.Println(rest.LastErrorText())
        rest.DisposeRest()
        return
    }

    //  FullRequestSb sends a request whose text body is read from a StringBuilder and stores the text
    //  response body in a second StringBuilder.  This avoids extra string conversions for large bodies.
    sbRequest := chilkat.NewStringBuilder()
    sbRequest.Append("{ \"query\": \"chilkat\" }")

    rest.AddHeader("Content-Type","application/json")

    sbResponse := chilkat.NewStringBuilder()
    success = rest.FullRequestSb("POST","/api/search",sbRequest,sbResponse)
    if success == false {
        fmt.Println(rest.LastErrorText())
        rest.DisposeRest()
        sbRequest.DisposeStringBuilder()
        sbResponse.DisposeStringBuilder()
        return
    }

    responseText := sbResponse.GetAsString()
    if sbResponse.LastMethodSuccess() == false {
        fmt.Println(sbResponse.LastErrorText())
        rest.DisposeRest()
        sbRequest.DisposeStringBuilder()
        sbResponse.DisposeStringBuilder()
        return
    }

    fmt.Println(*responseText)

    rest.DisposeRest()
    sbRequest.DisposeStringBuilder()
    sbResponse.DisposeStringBuilder()