Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Jul 22, 2024. It is now read-only.

Commit d812c04

Browse files
authored
Merge pull request #8 from IBM/update_for_oscon
Update for oscon
2 parents e50844b + 03971bc commit d812c04

File tree

1 file changed

+40
-43
lines changed

1 file changed

+40
-43
lines changed

‎README.md

Lines changed: 40 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -14,27 +14,25 @@ Create a file named `create-cat.js`. This file will define an OpenWhisk action w
1414
```javascript
1515
function main(params) {
1616

17-
console.log(params.name);
18-
console.log(params.color);
19-
20-
if (!params.name) {
21-
console.error('name parameter not set.');
22-
return {
23-
headers: {
24-
'Content-Type': 'application/json'
25-
},
26-
statusCode: 400,
27-
body: {"error": "Name parameter not set"}
17+
return new Promise(function(resolve, reject) {
18+
console.log(params.name);
19+
console.log(params.color);
20+
21+
if (!params.name) {
22+
console.error('name parameter not set.');
23+
reject({
24+
'error': 'name parameter not set.'
25+
});
26+
return;
27+
} else {
28+
resolve({
29+
statusCode: 201,
30+
id: 1
31+
});
32+
return;
2833
}
29-
} else {
30-
return {
31-
headers: {
32-
'Content-Type': 'application/json'
33-
},
34-
statusCode: 200,
35-
body: {"id": "1"}
36-
}
37-
}
34+
35+
});
3836

3937
}
4038
```
@@ -43,36 +41,35 @@ Create a file named `fetch-cat.js`. This file will define an OpenWhisk action wr
4341
```javascript
4442
function main(params) {
4543

46-
console.log(params.name);
47-
console.log(params.color);
48-
49-
if (!params.id) {
50-
console.error('id parameter not set.');
51-
return {
52-
headers: {
53-
'Content-Type': 'application/json'
54-
},
55-
statusCode: 400,
56-
body: {"error": "Name parameter not set"}
44+
return new Promise(function(resolve, reject) {
45+
console.log(params.id);
46+
47+
if (!params.id) {
48+
console.error('id parameter not set.');
49+
reject({
50+
'error': 'id parameter not set.'
51+
});
52+
return;
53+
} else {
54+
resolve({
55+
statusCode: 200,
56+
id: 1,
57+
name: 'Tahoma',
58+
color: 'Tabby'
59+
});
60+
return;
5761
}
58-
} else {
59-
return {
60-
headers: {
61-
'Content-Type': 'application/json'
62-
},
63-
statusCode: 200,
64-
body: {"id": "1", "name": "Tahoma", "color": "Tabby"}
65-
}
66-
}
62+
63+
});
6764

6865
}
6966
```
7067

7168
## Upload actions and test
72-
The next step will be to create OpenWhisk actions from the JavaScript functions that we just created. To create an action, use the wsk CLI command: `wsk action create [action name] [JavaScript file] --web true`
69+
The next step will be to create OpenWhisk actions from the JavaScript functions that we just created. To create an action, use the wsk CLI command: `wsk action create [action name] [JavaScript file]`
7370
```bash
74-
wsk action update create-cat create-cat.js --web true
75-
wsk action update fetch-cat fetch-cat.js --web true
71+
wsk action update create-cat create-cat.js
72+
wsk action update fetch-cat fetch-cat.js
7673
```
7774
OpenWhisk actions are stateless code snippets that can be invoked explicitly or in response to an event. For right now, we will test our actions by explicitly invoking them. Later, we will trigger our actions in response to an HTTP request. Invoke the actions using the code below and pass the parameters using the `--param` command line argument.
7875

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /