func(live)

Contributing

This page explains how you can contribute a function to func.live.

For the sake of illustration we'll pretend we want to submit the base64Encode function, which already exists here.

1. Build your function

Step one is to build the function and to expose it via a URL endpoint.

To build the base64Encode function, we could write an express app with a handler like this:

export const base64Encode = async(req,res) =>{
  const {input} = req.body
  const output = Buffer.from(input).toString('base64')
  res.send({output})
}

👉 Note that:

  • the input needs to always be provided as the input property of the req.body (i.e. the request payload needs to look like this: { input:... })
  • your function should respond with a JSON payload that provides the output under the output key. For example, if your function returns the number 42 {output:42}

2. Write your docs

We need a second endpoint that makes your functions docs available. The docs are a JSON object. For our base64Encode example the docs would looks like this:

{
  "name": "base64Encode",
  "description": "Encode anything to base64",
  "input": {
    "type": "string",
    "description": "Input the data you'd like to encode to base64",
    "example": "Hello, world"
  },
  "output": {
    "type": "string",
    "description": "Base64 encoded string",
    "example": "SGVsbG8sIHdvcmxk"
  }
}

👉 Note that the input and output fields are in the jsonschema format that explains what the input and the output of the function need to looks like. Each field should have a type, description and example value, as shown.

3. Deploy your function

Next step is to deploy your function to a publically available URL. Most funcs are cloud functions. For example, for GCP you could use this.

Your docs and the function itself need to live on the same endpoint. The docs under the GET method, the function itself under the POST method.

  1. GET https://your.url/functions/base64Encode -> returns the docs
  2. POST https://your.url/functions/base64Encode -> returns the output

4. Now submit your function

Make a post request like the one below:


curl -X POST https://api.func.live/functions \
   -H "Content-Type: application/json" \
   -H "Authorization: Bearer <FUNC_TOKEN>" \
   -d "{\"url\":\"YOUR_FUNC_URL\"}"

where:

  • FUNC_TOKEN is a token that identifies you. You can get this at https://tokens.wakeflow.io
  • YOUR_FUNC_URL is the url under which your function is available. In our example, that's https://your.url/functions/base64Encode

💪 Done

We will then review your function and let you know once it is live.

Any questions

Please email contact@wakeflow.io

awakeflow logoservice
v1.0.1
Having trouble? Try our
whatsapp logo
Whatsapp Support