C
C
Simple GET using REST
See more REST Examples
Demonstrates how to do a simple HTTP GET request using REST.Chilkat C Downloads
#include <C_CkRest.h>
void ChilkatSample(void)
{
BOOL success;
HCkRest rest;
BOOL bTls;
int port;
BOOL bAutoReconnect;
const char *responseJson;
success = FALSE;
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
rest = CkRest_Create();
// Connect to the REST server.
bTls = TRUE;
port = 443;
bAutoReconnect = TRUE;
success = CkRest_Connect(rest,"my-store.com",port,bTls,bAutoReconnect);
responseJson = CkRest_fullRequestNoBody(rest,"GET","/wp-json/wc/v1/products?consumer_key=YOUR_CONSUMER_KEY&consumer_secret=YOUR_CONSUMER_SECRET");
if (CkRest_getLastMethodSuccess(rest) != TRUE) {
printf("%s\n",CkRest_lastErrorText(rest));
CkRest_Dispose(rest);
return;
}
printf("%s\n",responseJson);
printf("----\n");
// We can alternatively do this:
CkRest_ClearAllQueryParams(rest);
CkRest_AddQueryParam(rest,"consumer_key","YOUR_CONSUMER_KEY");
CkRest_AddQueryParam(rest,"consumer_secret","YOUR_CONSUMER_SECRET");
responseJson = CkRest_fullRequestNoBody(rest,"GET","/wp-json/wc/v1/products");
if (CkRest_getLastMethodSuccess(rest) != TRUE) {
printf("%s\n",CkRest_lastErrorText(rest));
CkRest_Dispose(rest);
return;
}
printf("%s\n",responseJson);
CkRest_Dispose(rest);
}