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 2cdcfae

Browse files
committed
Update simple getting started for OSCON.
1 parent 0c9ad61 commit 2cdcfae

File tree

1 file changed

+43
-40
lines changed

1 file changed

+43
-40
lines changed

‎README.md

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

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;
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"}
3328
}
34-
35-
});
29+
} else {
30+
return {
31+
headers: {
32+
'Content-Type': 'application/json'
33+
},
34+
statusCode: 200,
35+
body: {"id": "1"}
36+
}
37+
}
3638

3739
}
3840
```
@@ -41,35 +43,36 @@ Create a file named `fetch-cat.js`. This file will define an OpenWhisk action wr
4143
```javascript
4244
function main(params) {
4345

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;
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"}
6157
}
62-
63-
});
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+
}
6467

6568
}
6669
```
6770

6871
## Upload actions and test
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]`
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`
7073
```bash
71-
wsk action create create-cat create-cat.js
72-
wsk action create fetch-cat fetch-cat.js
74+
wsk action update create-cat create-cat.js --web true
75+
wsk action update fetch-cat fetch-cat.js --web true
7376
```
7477
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.
7578

0 commit comments

Comments
(0)

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