{"id":19865627,"url":"https://github.com/openfaas/function-builder-examples","last_synced_at":"2025-05-02T05:31:45.285Z","repository":{"id":37451783,"uuid":"499406068","full_name":"openfaas/function-builder-examples","owner":"openfaas","description":" OpenFaaS Pro function builder API examples","archived":false,"fork":false,"pushed_at":"2025-03-14T10:26:28.000Z","size":28,"stargazers_count":10,"open_issues_count":0,"forks_count":4,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-06T23:08:03.252Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://docs.openfaas.com/openfaas-pro/builder/","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/openfaas.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-06-03T06:37:03.000Z","updated_at":"2025-03-14T10:26:32.000Z","dependencies_parsed_at":"2024-11-12T19:31:21.619Z","dependency_job_id":null,"html_url":"https://github.com/openfaas/function-builder-examples","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/openfaas%2Ffunction-builder-examples","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/openfaas%2Ffunction-builder-examples/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/openfaas%2Ffunction-builder-examples/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/openfaas%2Ffunction-builder-examples/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/openfaas","download_url":"https://codeload.github.com/openfaas/function-builder-examples/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251992913,"owners_count":21677022,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-12T15:23:29.427Z","updated_at":"2025-05-02T05:31:40.276Z","avatar_url":"https://github.com/openfaas.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# OpenFaaS Pro Function Builder API examples\nThis repo contains some code examples that show you how to use the [OpenFaaSFunction Builder API](https://docs.openfaas.com/openfaas-pro/builder/) from different languages.\n\n\u003e The Function Builder API provides a simple REST API to create your functions from source code.\n\u003e See [Function Builder API docs](https://docs.openfaas.com/openfaas-pro/builder/) for installation instructions\n\nBefore attempting to run the examples make sure the pro-builder is port-forwarded to port 8081 on the local host.\n\n```bash\nkubectl port-forward \\\n    -n openfaas \\\n    svc/pro-builder 8081:8080\n```\n\nSave the HMAC signing secret created during the installation to a file `payload.txt` at the root of this repo.\n```bash\nkubectl get secret \\\n    -n openfaas payload-secret -o jsonpath='{.data.payload-secret}' \\\n    | base64 --decode \\\n    \u003e payload.txt\n```\n\nThe directory [hello-world](./hello-world/) can be passed as the handler directory to the examples. It contains a javascript handler for a function. The hello-world directory was created by running:\n\n```bash\nfaas-cli new hello-world --lang node20\n```\n\nYou can use the `faas-cli` to create any other handler to try these example scripts with.\n\n## Use Python to call the pro-builder\n\nThe [python-request](./python-request/) directory has an example on how to invoke the Function Builder API from python. Run the `build.py` script with the required flags to turn a function handler into a container image.\n\nThe python script uses the [Requests](https://requests.readthedocs.io/en/latest/) package so you will have to install that to run the example.\n\n```\nsudo python3 -m pip install requests\n```\n\nRun the script\n```bash\npython3 python-request/build.py \\\n    --image ttl.sh/hello-world-python:1h \\\n    --handler ./hello-world \\\n    --lang node20\n```\n\n## Use NodeJS to call the pro-builder\nThe [nodejs-request](./nodejs-request/) directory has an example on how to invoke the Function Builder API from NodeJS. Run the `index.js` script with the required arguments to turn a function handler into a container image.\n\nInstall the required packages\n```bash\ncd nodejs-request\nnpm install\n```\n\nThe script takes three arguments:\n- The docker image name to build\n- A directory with the handler for the function\n- The language or template to use\n\n```bash\nnode nodejs-request/index.js \\\n    'ttl.sh/hello-world-node:1h' \\\n    ./hello-world \\\n    node20\n```\n\n## Use php to call the pro-builder\nThe [php-request](./php-request/) directory has an example on how to invoke the Function Builder API from php. Run the `build.php` script with the required arguments to turn a function handler into a container image.\n\nInstall the required packages\n```bash\ncd php-request\nphp composer.phar install\n```\n\nThe script takes three arguments:\n- The docker image name to build\n- A directory with the handler for the function\n- The language or template to use\n\n```bash\nphp php-request/build.php \\\n    --image=ttl.sh/hello-world-php:1h \\\n    --handler=./hello-world \\\n    --lang=node20\n```\n\n## Use go and the OpenFaaS go-sdk to call the pro-builder\nThe [go-request](./go-request/) directory has an example on how to invoke the Function Builder API from go using the official OpenFaaS go-sdk. Run the `main.go` script with the required flags to turn a function handler into a container image.\n\nThe example script does not fetch templates. How this is done is up to your implementation. Templates can be pulled from a git repository, copied from an S3 bucket, downloaded with an http call.\n\nTo try out this example you can fetch them using the faas-cli before running the script:\n```sh\nfaas-cli template store pull node20\n```\n\nRun the script\n```bash\ngo run go-request/main.go \\\n    -image=ttl.sh/hello-world-go:1h \\\n    -handler=./hello-world \\\n    -lang=node20 \\\n    -name=\"hello-world\" \\\n    -platforms=\"linux/amd64\"\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fopenfaas%2Ffunction-builder-examples","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fopenfaas%2Ffunction-builder-examples","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fopenfaas%2Ffunction-builder-examples/lists"}