Library
| Name |
RESTClient |
| Examples |
import com.francisli.processing.restclient.*;
RESTClient client;
void setup() {
client = new RESTClient(this, "www.googleapis.com");
client.useSSL = true;
client.GET("/books/v1/volumes?q=isbn:0747532699");
}
void responseReceived(HttpRequest request, HttpResponse response) {
println(response.getContentAsString());
}
void draw() {
}
|
| Description |
The RESTClient class provides the interface for performing different types
of HTTP requests against a particular server. Instantiate a new RESTClient
object for each server you wish to communicate with.
Requests are performed in the background and responses are returned in a
callback function with the following signature:
void responseReceived(HttpRequest request, HttpResponse response) {
}
Because requests are performed in the background, it is important that
you have a draw() function defined (even if it is empty, as shown in the
example above) and the animation loop is running. Without a draw() function,
Processing will terminate the sketch after setup(), which will shutdown
all connections. If the animation loop is not running, you will never get
a responseReceived() callback. The library will invoke your responseReceived()
callback at the beginning of a frame, before your draw() function is called. |
| Fields |
| useSSL |
boolean: set true to use SSL encryption |
| logging |
boolean: set false to turn off logging information in the console |
| useOAuth |
boolean: set true to sign requests using OAuth |
| oauthConsumerKey |
String: the OAuth consumer key assigned to you for your app |
| oauthConsumerSecret |
String: the OAuth consumer secret assigned to you for your app |
| oauthAccessToken |
String: the OAuth access token for a user of your app |
| oauthAccessTokenSecret |
String: the OAuth access token secret for a user of your app |
|
| Methods |
| GET() |
Performs a GET request to fetch content from the specified path. |
| POST() |
Performs a POST request, sending the specified parameters as data
in the same way a web browser submits a form. |
| setBearerAuthorizationHeader() |
Sets the HTTP Authorization header with a Bearer token value. |
| setHeader() |
Sets a new HTTP header that will be applied to every outgoing request. |
|
| Constructor |
RESTClient(parent, hostname)
RESTClient(parent, hostname, port)
RESTClient(parent, hostname, port, securePort)
|
| Parameters |
| parent |
PApplet: typically use "this" |
| hostname |
String: the domain name or IP address of the host |
| port |
int: the port to use for unsecured connections (typically 80) |
| securePort |
int: The port to use for secure connections (typically 443) |
|
| Usage |
Application |
Updated on Sun Sep 03 21:52:12 PDT 2017