✈️ functions in the cloud with rest api. Test site ->
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.build new build files Apr 25, 2017
client fix invocations not displaying Apr 25, 2017
server
.eslintignore init project Mar 17, 2017
.eslintrc.json
.gitignore ignore dist Mar 24, 2017
README.md Added more globals May 7, 2017
ff.png

README.md

flying-functions

Your functions in the cloud with rest api

Usage

Summary

Basic how to

  1. write your function like this.
module.exports = async (data) => {
  // your code here 

  // example
  return 10; 
};
  1. post it to flying functions like example in API bellow.
  2. execute url from response.
  3. Response from server executing function above.
{
  "result": 10,
  "invocations": 1,
  "self": "URL TO SELF" 
}

Flying function params

Syntax

module.exports = async (data) => {}

Parameters

  • data
    • express req.query (GET) or express req.data (POST)

Globals

these globals are accessible from your flying function

  • console
  • Number
  • Math
  • Promise
  • setTimeout
  • fetch
    • isomorphic-fetch from npm
  • R
    • ramda from npm
  • plura
    • plura from npm
  • flaxa
    • flaxa from npm
  • laiva
    • laiva from npm
  • timeeditApi
    • timeeditApi from npm
  • destructo
    • destructo from npm
  • storageHandler
    • Persistent storage handler
  • _requestOrigin
    • What origin is the request from
  • _flyingFunctionData
    • Object with data about your flying function, contains:
      • name.
      • urlId
      • secretId
      • invocations:
        • nr of times function has been invocated (including current)
      • HTTPType

Persistent Storage

use the global storageHandler to manipulate data

Overview

create

Syntax

const result = await storageHandler.create(collectionId, dataToStore)

Parameters

  • collectionId: string
    • used to store your data under a shared id so you can retirve large collections of that data.
  • dataToStore: object
    • the data you want to store.

Return value

Object stored in the database

getById

Syntax

const result = await storageHandler.getById(id)

Parameters

  • id: string
    • Id for specific resource.

Return value

Object stored in the database

getByCollectionId

Syntax

const result = await storageHandler.getByCollectionId(id)

Parameters

  • id: string
    • Id of a collection id.

Return value

An Array of multible objects that are stored under the same collection id.

updateDataById

Syntax

const result = await storageHandler.updateDataById(id, data)

Parameters

  • id: string
    • Id of a specific resource.
  • data: object
    • object of data to be uppdated.

Return value

Updated object that is stored in the database.

remove

Syntax

const result = await storageHandler.remove(id)

Parameters

  • id: string
    • Id of a specific resource

Return value

Object confirming the removal.

example

module.exports = async (data currentInvocation, flyingId) => {
  // all your saved data will be stored with an collection id 
  // so you can retrive all data within an collection
  const collectionId = flyingId

  // data to store has to be object
  const dataToStore = {
    value: 10,
  };

  const storedData = await flyingStorageHandler.create(collectionId, dataToStore)
  const storedData2 = await flyingStorageHandler.create(collectionId, { value: 11 })
  // returns storedData object, _id, collectionId, timestamps
  await flyingStorageHandler.getById(storedData._id)
  // returns array of all stored objects on collectionId
  await flyingStorageHandler.getByCollectionId(collectionId) 

  return storedData
};

API

flying functions api

GET - /flying/
view all stored functions - dev only
Responce:

[
  "ARRY WITH OBJECTS JUST LIKE (GET - /flying/:id)"
]

GET - /flying/:secretId
info about flying function
Responce:

{
  "_id": "ID OF FLYING FUNCTION",
  "secretId": "SECRET ID TO REMOVE/UPDATE/VIEW",
  "name": "NAME OF FLYING FUNCTION",
  "code": "CODE FOR FLYING FUNCTION",
  "HTTPType": "HTTP REQUEST TYPE FOR YOUR FLYING FUNCTION", 
  "invocations": "NUMBER OF INVOCATIONS FOR FLYING FUNCTION",
  "createdAt": "TIME OF CREATION",
  "updatedAt": "TIME OF LATEST UPDATE",
  "invocationUrl": "URL TO INVOC FLYING FUNCTION",
  "self": "URL TO SELF"
}

GET - /flying/:urlId/:name
invoc flying function
Send flying functions params in query
Responce:

{
  "result": "RESULT FROM FLYING FUNCTION",
  "invocations": "NUMBER OF INVOCATIONS FOR FLYING FUNCTION",
  "self": "URL TO SELF"
}

POST - /flying/:urlId/:name
invoc flying function
Send flying functions params in body
Responce:

{
  "result": "RESULT FROM FLYING FUNCTION",
  "invocations": "NUMBER OF INVOCATIONS OF FLYING FUNCTION",
  "self": "URL TO SELF"
}

POST - /flying/
creates a new flying function
Send json object to create flying function

{
  "name": "YOUR FLYING FUNCTION NAME",
  "code": "CODE FOR FLYING FUNCTION",
  "HTTPType":  "HTTP REQUEST TYPE FOR YOUR FLYING FUNCTION"
}

Responce:

{
  "invocationUrl": "URL TO INVOC FLYING FUNCTION",
  "urlId": "ID ONLY USED TO INVOC FLYING FUNCTION",
  "secretId": "SECRET ID TO REMOVE/UPDATE/VIEW",
  "name": "NAME OF FLYING FUNCTION",
  "HTTPType": "HTTP REQUEST TYPE FOR YOUR FLYING FUNCTION"
}

PUT - /flying/:secretId
updates a flying function
Send json object to update flying function

{
  "code": "CODE FOR FLYING FUNCTION"
}

Responce:

{
  "message": "Flying function updated"
}

DELETE - /flying/:secretId
removes flying function

Responce:

{
  "message": "Flying function removed"
}

Webhook api

POST - /webhook/:urlId
creates a new webhook
Send json object to create webhook

{
  "url": "WEBHOOK URL"
}

Responce:

{
  "url": "WEBHOOK URL",
  "id": "ID OF WEBHOOK",
}

DELETE - /webhook/:id
removes webhook

Responce:

{
  "secretId": "SECRET ID OF REMOVED FLYING FUNCTION",
  "message": "webhook removed!"
}

TODO

general

  • Code cleanup

doc

client

  • Validation messages
  • Add button to show available globals and examples
  • Localstorage for previously create flying functions and webhooks.

server

  • Add more globals
  • Add better api error messages