Over a million developers have joined DZone.

Playin' Around with PiCloud's REST API

· Cloud Zone

Download the Essential Cloud Buyer’s Guide to learn important factors to consider before selecting a provider as well as buying criteria to help you make the best decision for your infrastructure needs, brought to you in partnership with Internap.

I was playing around with PiCloud’s REST API and had a bit of fun writing a C client for it. Now, why C? Well, because one of the reasons they provide a REST API is for your non-Python programs to easily access your Python code on PiCloud.

What I did is simple: I published the square_func using PiCloud’s documentation. Then I used libcurl’s C Interface to replicate the curl statements provided in the documentation. I have
written the client in two parts: client1.c and client2.c. client1.c invokes the published function, hence gets the Job ID. client2.c then uses this jobID to get the result. Here are the source codes:

/* This part of the client invokes the REST API of
   PiCloud and retrieves the Job ID

#include <stdio.h>
#include <curl/curl.h>

int main(void)
  CURL *curl;

  /* Make sure you set this appropriately*/
  char *url="https://api.picloud.com/r/3222/square_func/";
  CURLcode res;
  curl = curl_easy_init();
  if(curl) {
    /* First set the URL that is about to receive our POST. This URL can
       just as well be a https:// URL if that is what should receive the
       data. */
    curl_easy_setopt(curl, CURLOPT_URL, url);
    /* Specify the user/pass */
    /* Now specify the POST data */
    curl_easy_setopt(curl, CURLOPT_POSTFIELDS, "x=5");
    /* For HTTPS */
    curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L);

    /* Perform the request, res will get the return code */
    res = curl_easy_perform(curl);
    printf("\nResult of Operation:: %d\n", res);

    /* always cleanup */
  return 0;


The Cloud Zone is brought to you in partnership with Internap. Read Bare-Metal Cloud 101 to learn about bare-metal cloud and how it has emerged as a way to complement virtualized services.


Published at DZone with permission of amit savant. See the original article here.

Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}