Skip to content

testdrivenio/openfass-node-restful-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

OpenFaaS RESTful API w/ Node and Postgres

Simple example of an OpenFaaS RESTful API.

Getting Started

Build the Docker images for the functions:

$ sh build.sh

Initialize Swarm mode:

$ docker swarm init

Deploy:

$ docker stack deploy func --compose-file docker-compose.yml --prune

Create database and movie table:

$ PG_CONTAINER_ID=$(docker ps --filter name=movies-db --format "{{.ID}}")
$ docker exec -ti $PG_CONTAINER_ID psql -U postgres -W
# CREATE DATABASE movies;
# \c movies
# CREATE TABLE movie(id SERIAL, name varchar);
# \q

Test:

$ curl -X POST http://localhost:8080/function/func_api-create -d \
  '{"name":"NeverEnding Story"}'

$ curl http://localhost:8080/function/func_api-read

$ curl -X POST http://localhost:8080/function/func_api-update -d \
  '{"name":"NeverEnding Story 2", "id": "1"}'

$ curl -X POST http://localhost:8080/function/func_api-delete -d \
  '{"id":"1"}'

Deploy to Digital Ocean

deploy-swarm.md