Sample code for 30+ languages & platforms
React Native

Simple GET using REST

See more REST Examples

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

Chilkat React Native Downloads

React Native
import { Rest } from '@chilkat/react-native'

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

  const rest = new Rest();

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

  let responseJson: string;
  try {
    responseJson = await rest.fullRequestNoBodyAsync('GET', '/wp-json/wc/v1/products?consumer_key=YOUR_CONSUMER_KEY&consumer_secret=YOUR_CONSUMER_SECRET');
  } catch {
    console.log(rest.lastErrorText);
    return;
  }

  console.log(responseJson);
  console.log('----');

  // We can alternatively do this:
  rest.clearAllQueryParams();
  rest.addQueryParam('consumer_key', 'YOUR_CONSUMER_KEY');
  rest.addQueryParam('consumer_secret', 'YOUR_CONSUMER_SECRET');
  try {
    responseJson = await rest.fullRequestNoBodyAsync('GET', '/wp-json/wc/v1/products');
  } catch {
    console.log(rest.lastErrorText);
    return;
  }

  console.log(responseJson);
}