GithubHelp home page GithubHelp logo

nicklasxyz / dart_openfaas Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 1.0 36 KB

Dart serverless templates to be used with OpenFaaS

License: Apache License 2.0

Dockerfile 19.28% Dart 80.72%
dart dartlang serverless openfaas openfaas-template openfaas-function template

dart_openfaas's Introduction

Dart OpenFaaS function templates

This repository contains OpenFaaS function templates for writing serverless functions in the Dart programming language.

Usage

  1. Make sure OpenFaaS has been deployed to your Kubernetes cluster and the OpenFaaS CLI tool has been installed. See here and here for a brief introduction on how to do this.

  2. Download the Dart function templates from this repo:

faas-cli template pull https://github.com/nicklasxyz/dart_openfaas#main
  1. Create a new function:
faas-cli new --lang dart test-function

Note: This essentially creates a usual Dart project stucture, but with a pre-defined package name and files. The main functionality should be implemented in the files contained in the newly created test-function/function directory. Extra dependencies should be added to the respectivepubspec.yaml files in the root of the test-function or the test-function/function directory. The project can be compiled and tested locally as usual. See the forllowing README.md for more information.

  1. Add new functionality to the function that is going to be deployed and managed by OpenFaaS:
code template/function/lib/src/function_base.dart
# ... Inside this file extend or add whatever you want to inside the 'Service' class  
  1. Make sure a valid container registry, to where functions can be pushed, has been defined in the test-function.yml file:
code test-function.yml
  1. Finally, build, push and deploy the function:
# Authenticate with OpenFaaS (assuming kubectl is used with the k3s Kubernetes distribution):
PASSWORD=$(k3s kubectl -n openfaas get secret basic-auth -o jsonpath="{.data.basic-auth-password}" | base64 --decode) && \
echo "OpenFaaS admin password: $PASSWORD"
faas-cli login --gateway http://localhost:31112 --password=$PASSWORD

# Build, push and deploy:
faas-cli build -f test-function.yml
faas-cli push -f test-function.yml
faas-cli deploy -f test-function.yml --gateway=http://localhost:31112

# ... or just:
faas-cli up -f test-function.yml --gateway=http://localhost:31112

# To remove function deployments run:
faas-cli remove -f test-function.yml --gateway=http://localhost:31112
  1. Wait a few seconds, then we can invoke the function by sending a request through curl:
### Example GET request
curl -k \
  -X GET http://localhost:31112/function/test-function; \
  echo

# If nothing was changed in the 'test-function/function' directory before
# deployment then we should just see the default response:
>> Hello from Dart & Openfaas!

### Example POST request:
curl -k \
  -d "{\"name\": \"Peter\", \"age\": \"42\", \"height\": \"180.5\"}" \
  -H "Content-Type: application/json" \
  -X POST http://localhost:31112/function/test-function; \
  echo

# If nothing was changed in the 'test-function/function' directory before
# deployment then we should just see the default response:
>> [{"string_field":"Peter"}, {"int_field":42}, {"double_field":180.5}]
  1. If we just want to check that the requests were handled properly then we can check the logs:
faas-cli logs test-function --gateway http://localhost:31112

The function can also be invoked through the public interface at http://localhost:31112/ui/ using username admin and the previously defined password contained in environment variable $PASSWORD.

dart_openfaas's People

Contributors

nicklasxyz avatar

Watchers

 avatar

Forkers

hypermodern-dev

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.