Sample code for 30+ languages & platforms
Dart

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 Dart Downloads

Dart
import 'package:chilkat/chilkat.dart';

void main() {
  final rest = CkRest();
  final bTls = true;
  final bAutoReconnect = true;
  try {
    rest.connect('example.com', 443, bTls, bAutoReconnect);
  } on ChilkatException catch (e) {
    print(e.lastErrorText);
    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.
  final sbRequest = CkStringBuilder();
  sbRequest.append('{ "query": "chilkat" }');

  rest.addHeader('Content-Type', 'application/json');

  final sbResponse = CkStringBuilder();
  try {
    rest.fullRequestSb('POST', '/api/search', sbRequest, sbResponse);
  } on ChilkatException catch (e) {
    print(e.lastErrorText);
    return;
  }

  final String responseText;
  try {
    responseText = sbResponse.getAsString();
  } on ChilkatException catch (e) {
    print(e.lastErrorText);
    return;
  }

  print(responseText);
}