CloudPlugs REST Client for PHP is a library to perform HTTP requests to CloudPlugs servers. The official repository is: https://github.com/cloudplugs/rest-php
Cloudplugs is a cloud based IoT platform to enable the fast prototyping, connection, deployment and management of smart "Things" (sensors, smartphones, home appliances, etc.). Different objects can interact with each other by publishing and/or reading any type of data on shared channels through simple communication protocols. You can learn more at http://www.cloudplugs.com/how-it-works/ and you can sign-up on http://www.cloudplugs.com/register to start connecting your Things.
Just include the library in your PHP script:
Use the Clouplugs platform's namespace:
Create a new instance:
Now you are ready to configure the library and invoke methods to perform REST requests to the server!
After you have a new instance of the class, there are a few configuration parameters that you can customize, if needed, before invoking any request. These parameters are:
You can set these options using the configuration methods as in the following example:
Or using the setOptions() method:
To enhance security, the library is configured to run over HTTPS by default. To establish an SSL connection with the Cloudplugs Platform, Cloudplugs's certificate (named 'cacert.pem'
) must be always present in the same directory of the library. You can choose whether to switch SSL mode on or off at any time by invoking the method enableSSL(bool)
. Example:
Even if Cloudplugs supports both HTTP and HTTPS, is strongly recommended to always run the library over HTTPS.
When your instance of the library is ready, you can execute HTTP requests to the server by invoking any of the request methods. All the requests are synchronous and are performed according to the Cloudplugs REST API documentation. Example: