Sample code for 30+ languages & platforms
Java

Simple GET using REST

See more REST Examples

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

Chilkat Java Downloads

Chilkat2 Java
import com.chilkatsoft.chilkat2.ChilkatException;
import com.chilkatsoft.chilkat2.Rest;

public class ChilkatExample {

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

        Rest rest = new Rest();

        // Connect to the REST server.
        boolean bTls = true;
        int port = 443;
        boolean 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");
        } catch (ChilkatException e) {
            System.out.println(e.getLastErrorText());
            return;
        }

        System.out.println(responseJson);
        System.out.println("----");

        // 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");
        } catch (ChilkatException e) {
            System.out.println(e.getLastErrorText());
            return;
        }

        System.out.println(responseJson);
    }
}