Skip to content
This repository was archived by the owner on Feb 4, 2020. It is now read-only.

Commit fa28bae

Browse files
committed
Updated README. Now uses openfaas instead of faas
Signed-off-by: austinfrey <[email protected]>
1 parent d52861b commit fa28bae

File tree

10 files changed

+188
-43
lines changed

10 files changed

+188
-43
lines changed

README.md

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
[![XO code
2+
style](https://img.shields.io/badge/code_style-XO-5ed9c7.svg)](https://github.com/sindresorhus/xo)
3+
![OpenFaaS](https://img.shields.io/badge/openfaas-serverless-blue.svg)
4+
5+
##### Usage
6+
7+
Add `openfaas` via `npm`
8+
9+
```
10+
$ npm install openfaas --save
11+
```
12+
13+
Example usage
14+
15+
```
16+
const OpenFaaS = require('./openfaas')
17+
18+
const openfaas = OpenFaaS('http://localhost:8080')
19+
20+
openfaas.deploy(
21+
'yolo', // name your function
22+
'func_functions, // choose your network
23+
'hello-serverless // choose the Docker image
24+
)
25+
.then(x => console.log(x))
26+
.catch(err => console.log(err))
27+
28+
openfaas.invoke(
29+
'yolo', // function name
30+
'hello world', // data to send to function
31+
true //should response be JSON? optional. default is false
32+
)
33+
.then(x => console.log(x)) // handle response
34+
.catch(err => console.log(err))
35+
36+
openfaas.remove('yolo')
37+
.then(x => console.log(x)) // handle response
38+
.catch(err => console.log(err))
39+
40+
openfaas.compose('initial data', [
41+
'func_nodeinfo',
42+
'func_echoit',
43+
'func_wordcount'
44+
]
45+
)
46+
.then(x => console.log(x.body)) // handle final output
47+
.catch(err => console.log(err))
48+
```
49+
50+
##### ToDo
51+
* Complete tests
52+
* support additional request options for `got`

index.js

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,4 @@
1-
const Faas = require('./faas');
1+
'use strict';
22

3-
const faas = Faas('http://localhost:8080');
4-
5-
faas.deploy(
6-
'yolo',
7-
'func_functions',
8-
'hello-serverless'
9-
)
10-
.then(x => console.log(x))
11-
.catch(err => console.log(err));
3+
module.exports = require('./openfaas');
124

File renamed without changes.
File renamed without changes.

faas/index.js renamed to openfaas/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ const remove = require('./remove');
55
const invoke = require('./invoke');
66
const compose = require('./compose');
77

8-
const faas = url => ({
8+
const OpenFaaS = url => ({
99
deploy: deploy(url),
1010
remove: remove(url),
1111
invoke: invoke(url),
1212
compose: compose(url)
1313
});
1414

15-
module.exports = faas;
15+
module.exports = OpenFaaS;
1616

faas/invoke.js renamed to openfaas/invoke.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,12 @@ const got = require('got');
66
const invoke = gateway => {
77
const url = gateway;
88

9-
return (name, data) => {
9+
return (name, data = null, isJson = false, isBinaryResponse = false) => {
1010
const funcPath = path.join('/function', name);
1111
const options = {
1212
method: 'POST',
13-
json: true
13+
json: isJson,
14+
encoding: (isBinaryResponse ? null : 'utf8')
1415
};
1516

1617
if (data) {
File renamed without changes.

package-lock.json

Lines changed: 77 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,33 @@
11
{
2-
"name": "open-faas",
3-
"version": "0.0.1",
4-
"description": "",
2+
"name": "openfaas",
3+
"version": "0.0.4",
4+
"description": "NodeJS wrapper around the OpenFaaS Gateway API w/ some additional helper functions",
55
"main": "index.js",
66
"scripts": {
7-
"test": "echo \"Error: no test specified\" && exit 1"
7+
"test": "node test",
8+
"lint": "xo --fix"
89
},
9-
"author": "",
10-
"license": "ISC",
10+
"author": "Austin Frey",
11+
"license": "MIT",
1112
"dependencies": {
1213
"bluebird": "^3.5.0",
1314
"got": "^7.1.0"
1415
},
1516
"devDependencies": {
17+
"nock": "^9.0.20",
1618
"tape": "^4.8.0",
1719
"xo": "^0.18.2"
18-
}
20+
},
21+
"repository": {
22+
"type": "git",
23+
"url": "git+https://github.com/austinfrey/node-openfaas.git"
24+
},
25+
"keywords": [
26+
"serverless",
27+
"FaaS"
28+
],
29+
"bugs": {
30+
"url": "https://github.com/austinfrey/node-openfaas/issues"
31+
},
32+
"homepage": "https://github.com/austinfrey/node-openfaas#readme"
1933
}

test.js

Lines changed: 31 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
'use strict';
22

33
const test = require('tape');
4-
const BbPromise = require('bluebird')
5-
const FaaS = require('./faas');
4+
const nock = require('nock');
5+
const BbPromise = require('bluebird');
6+
const FaaS = require('./openfaas');
67

78
test('Test typeofs', t => {
89
t.plan(6);
@@ -12,37 +13,47 @@ test('Test typeofs', t => {
1213
const faas = FaaS('http://localhost:8080');
1314

1415
t.equals(typeof faas, 'object');
15-
t.equals(typeof faas.deploy, 'function')
16-
t.equals(typeof faas.invoke, 'function')
17-
t.equals(typeof faas.compose, 'function')
18-
t.equals(typeof faas.remove, 'function')
19-
})
16+
t.equals(typeof faas.deploy, 'function');
17+
t.equals(typeof faas.invoke, 'function');
18+
t.equals(typeof faas.compose, 'function');
19+
t.equals(typeof faas.remove, 'function');
20+
});
2021

2122
test('Test full API', t => {
22-
t.plan(4)
23-
const faas = FaaS('http://localhost:8080')
2423

25-
const delay = (time) => {
26-
return new BbPromise(resolve => {
27-
setTimeout(resolve, time)
28-
})
29-
}
24+
nock('http://localhost:8080')
25+
.post('/system/functions', {
26+
service: 'test-func',
27+
network: 'func_functions',
28+
image: 'hello-serverless'
29+
}).reply(200)
30+
.post('/function/test-func').reply(200, {status: 'done'})
31+
.post('/function/func_nodeinfo').reply(200, 'hello cruel world')
32+
.post('/function/func_echoit', 'hello cruel world').reply(200, 'hello cruel world')
33+
.post('/function/func_wordcount', 'hello cruel world').reply(200, 3)
34+
.delete('/system/functions', {functionName: 'test-func'}).reply(200);
35+
36+
t.plan(5);
37+
const faas = FaaS('http://localhost:8080');
3038

3139
faas.deploy(
3240
'test-func',
3341
'func_functions',
3442
'hello-serverless'
3543
)
3644
.then(x => t.equals(x.statusCode, 200))
37-
.then(() => delay(5000).then(() => faas.invoke('test-func')))
45+
.then(() => faas.invoke('test-func',null, true))
3846
.then(x => t.same(x.body, {status: 'done'}))
3947
.then(() => faas.compose('', [
40-
'func_nodeinfo',
41-
'func_echoit',
42-
'func_wordcount'
43-
]
48+
'func_nodeinfo',
49+
'func_echoit',
50+
'func_wordcount'
51+
]
4452
))
45-
.then(x => t.equals(x.statusCode, 200))
53+
.then(x => {
54+
t.equals(x.statusCode, 200)
55+
t.equals(x.body, '3')
56+
})
4657
.then(() => faas.remove('test-func'))
4758
.then(x => t.equals(x.statusCode, 200))
4859
.catch(err => console.log(err));

0 commit comments

Comments
 (0)