Your functions in the cloud with rest api
- Basic how to
- Flying function params
- Globals
- Persistent Storage
- Api
- Flying function Api
- Webhook Api
- Todo
- write your function like this.
module.exports = async (data) => {
// your code here
// example
return 10;
};
- post it to flying functions like example in API bellow.
- execute url from response.
- Response from server executing function above.
{
"result": 10,
"invocations": 1,
"self": "URL TO SELF"
}
module.exports = async (data) => {}
- data
- express req.query (GET) or express req.data (POST)
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
- Object with data about your flying function, contains:
use the global storageHandler
to manipulate data
const result = await storageHandler.create(collectionId, dataToStore)
- 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.
Object stored in the database
const result = await storageHandler.getById(id)
- id: string
- Id for specific resource.
Object stored in the database
const result = await storageHandler.getByCollectionId(id)
- id: string
- Id of a collection id.
An Array of multible objects that are stored under the same collection id.
const result = await storageHandler.updateDataById(id, data)
- id: string
- Id of a specific resource.
- data: object
- object of data to be uppdated.
Updated object that is stored in the database.
const result = await storageHandler.remove(id)
- id: string
- Id of a specific resource
Object confirming the removal.
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
};
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"
}
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!"
}
- Code cleanup
- Validation messages
- Add button to show available globals and examples
- Localstorage for previously create flying functions and webhooks.
- Add more globals
- Add better api error messages