Sample code for 30+ languages & platforms
Go

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 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
    }

    //  FullRequestNoBodySb sends a request with no body and stores the text response body in a
    //  StringBuilder.
    sbResponse := chilkat.NewStringBuilder()
    success = rest.FullRequestNoBodySb("GET","/api/items/123",sbResponse)
    if success == false {
        fmt.Println(rest.LastErrorText())
        rest.DisposeRest()
        sbResponse.DisposeStringBuilder()
        return
    }

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

    fmt.Println(*responseText)

    rest.DisposeRest()
    sbResponse.DisposeStringBuilder()