Sample code for 30+ languages & platforms
Dart

Simple GET using REST

See more REST Examples

Demonstrates how to do a simple HTTP GET request using REST.

Chilkat Dart Downloads

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

void main() {
  // This example requires the Chilkat API to have been previously unlocked.
  // See Global Unlock Sample for sample code.

  final rest = CkRest();

  // Connect to the REST server.
  final bTls = true;
  final port = 443;
  final bAutoReconnect = true;
  rest.connect('my-store.com', port, bTls, bAutoReconnect);

  String responseJson;
  try {
    responseJson = rest.fullRequestNoBody('GET', '/wp-json/wc/v1/products?consumer_key=YOUR_CONSUMER_KEY&consumer_secret=YOUR_CONSUMER_SECRET');
  } on ChilkatException catch (e) {
    print(e.lastErrorText);
    return;
  }

  print(responseJson);
  print('----');

  // We can alternatively do this:
  rest.clearAllQueryParams();
  rest.addQueryParam('consumer_key', 'YOUR_CONSUMER_KEY');
  rest.addQueryParam('consumer_secret', 'YOUR_CONSUMER_SECRET');
  try {
    responseJson = rest.fullRequestNoBody('GET', '/wp-json/wc/v1/products');
  } on ChilkatException catch (e) {
    print(e.lastErrorText);
    return;
  }

  print(responseJson);
}