Managing Cloud Functions Programmatically

Managing Cloud Functions Programmatically

Telerik Platform provides RESTful endpoints for managing Cloud Function metadata and code.

For setting execution permissions see Setting Business Logic Permissions.

Creating Cloud Functions

To create a cloud function you need to supply a Name and Title.

Request:
    POST https://api.everlive.com/v1/Metadata/Applications/your-app-id/CloudFunctions
Headers:
    Content-Type: application/json
    Authorization: Masterkey your-master-key
Payload-raw
    { 
      "Name" : "MyFunction", 
      "Title" : "My Function"
    }
Response:
    Status: 200 OK
    Content-Type: application/json
Payload - raw:
    {
      "Result": {
        "Id": "fc1a51c0-4cd0-11e5-ad90-49e443189220",
        "CreatedAt": "2014-10-27T15:33:37.116Z"
      }
    }

You can also create multiple cloud functions by sending an array with the definition objects as a body of the request.

Reading Cloud Functions

To get all cloud functions registered in your app use the following endpoint.

Request:
    GET https://api.everlive.com/v1/Metadata/Applications/your-app-id/CloudFunctions
Headers:
    Content-Type: application/json
    Authorization: Masterkey your-master-key
Response:
    Status: 200 OK
    Content-Type: application/json
Payload - raw:
    {
      "Count": 1,
      "Result": [
        {
          "CreatedAt": "2014-10-27T11:57:12.032Z",
          "ModifiedAt": "2014-11-03T13:58:21.861Z",
          "ModifiedBy": "00000000-0000-0000-0000-000000000000",
          "Name": "getAuthenticationStatusForUser",
          "Id": "62cfbe00-5dd0-11e4-87c0-e571aba04699"
        }
      ]
    }

To get a cloud function by Id you can use the above request after suffixing the URL with the Id of a given cloud function.

To get the count of the cloud functions registered in your app use the above request after suffixing the URL with _count.

To get a cloud function by filter supply a request header with a filter definition according to the Filtering API .

X-Everlive-Filter: {"CreatedAt": {"$lte":"2014-10-27T11:56:12.032Z"}}

Reading Cloud Functions Code

To get the cloud code associated with a certain content type you need the Id of the cloud function and pass it in the URL, followed by "/Code".

Request:
    GET https://api.everlive.com/v1/Metadata/Applications/your-app-id/CloudFunctions/cloud-function-id/Code
Headers:
    Content-Type: application/json
    Authorization: Masterkey your-master-key
Response:
    Status: 200 OK
    Content-Type: application/javascript
    Content-Disposition: attachment; filename=main.js

Setting Cloud Functions Code

You can set cloud code by directly supplying the code implementation as a string in the body of the request.

Request:
    PUT https://api.everlive.com/v1/Metadata/Applications/your-app-id/CloudFunctions/cloud-function-id/Code
Headers:
    Content-Type: application/json
    Authorization: Masterkey your-master-key
Payload-raw
    {
        "Filename":"myCloudCode.txt",
        "Content-Type": "text/plain;",
        "Code": "Everlive.CloudFunction.onRequest(function(request, response, done){     console.log(\"Hello cloud functions\"); done();});"
    }
Response:
    Status: 200 OK
    Content-Type: application/json
Payload - raw:
    {
      "Count": 1,
      "Result": [
        {
          "CreatedAt": "2014-10-27T11:57:12.032Z",
          "ModifiedAt": "2014-11-03T13:58:21.861Z",
          "ModifiedBy": "00000000-0000-0000-0000-000000000000",
          "Name": "getAuthenticationStatusForUser",
          "Id": "62cfbe00-5dd0-11e4-87c0-e571aba04699"
        }
      ]
    }

Alternatively you can upload a file as a multipart/form-data stream to the same endpoint.

Updating Cloud Functions

The following request updates the Name and Title of a cloud function.

Request:
    PUT https://api.everlive.com/v1/Metadata/Applications/your-app-id/CloudFunctions/cloud-function-id
Headers:
    Content-Type: application/json
    Authorization: Masterkey your-master-key
Payload-raw
    { 
      "Name" : "MyFunction1", 
      "Title" : "My Function1"
    }
Response:
    Status: 200 OK
    Content-Type: application/json
Payload - raw:
    {
      "Result": 1
    }

Deleting Cloud Functions

You cannot delete all cloud functions at once or by filter.

To delete a cloud function by Id you can use the above request after suffixing the URL with the Id of a given cloud function. Alternatively, you can supply the Name of the cloud function instead of its Id.

Request:
    DELETE https://api.everlive.com/v1/Metadata/Applications/your-app-id/CloudFunctions/cloud-function-id
Headers:
    Content-Type: application/json
    Authorization: Masterkey your-master-key
Response:
    Status: 200 OK
    Content-Type: application/json

See Also

Start a free trial Request a demo
Contact us: +1-888-365-2779
sales@telerik.com
Copyright © 2016-2017, Progress Software Corporation and/or its subsidiaries or affiliates. All rights reserved.