You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Jul 22, 2024. It is now read-only.
Copy file name to clipboardExpand all lines: README.md
+15-23Lines changed: 15 additions & 23 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -17,21 +17,15 @@ Create a file named `create-cat.js`. This file will define an OpenWhisk action w
17
17
functionmain(params) {
18
18
19
19
returnnewPromise(function(resolve, reject) {
20
-
console.log(params.name);
21
-
console.log(params.color);
22
20
23
21
if (!params.name) {
24
-
console.error('name parameter not set.');
25
22
reject({
26
23
'error':'name parameter not set.'
27
24
});
28
-
return;
29
25
} else {
30
26
resolve({
31
-
statusCode:201,
32
27
id:1
33
28
});
34
-
return;
35
29
}
36
30
37
31
});
@@ -44,22 +38,17 @@ Create a file named `fetch-cat.js`. This file will define an OpenWhisk action wr
44
38
functionmain(params) {
45
39
46
40
returnnewPromise(function(resolve, reject) {
47
-
console.log(params.id);
48
41
49
42
if (!params.id) {
50
-
console.error('id parameter not set.');
51
43
reject({
52
44
'error':'id parameter not set.'
53
45
});
54
-
return;
55
46
} else {
56
47
resolve({
57
-
statusCode:200,
58
-
id:1,
48
+
id:params.id,
59
49
name:'Tahoma',
60
50
color:'Tabby'
61
51
});
62
-
return;
63
52
}
64
53
65
54
});
@@ -70,9 +59,11 @@ function main(params) {
70
59
## Upload actions and test
71
60
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]`
We've also added the flag, `--web true`, to annotate these actions as "Web Actions". This will be necessary later when we add REST endpoints.
66
+
76
67
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.
77
68
78
69
```bash
@@ -92,36 +83,37 @@ wsk action invoke \
92
83
93
84
# 2. Create REST endpoints
94
85
## Create POST and GET REST mappings for `/v1/cat` endpoint
95
-
Now that we have our OpenWhisk actions created, we will expose our OpenWhisk actions through the OpenWhisk API Gateway. To do this we will use: `wsk api-experimental create ([BASE_PATH] API_PATH API_VERB ACTION] [API PATH]`
96
-
This feature is currently experimental to enable users an early opportunity to try it out and provide feedback
86
+
Now that we have our OpenWhisk actions created, we will expose our OpenWhisk actions through the OpenWhisk API Gateway. To do this we will use: `wsk api create ([BASE_PATH] API_PATH API_VERB ACTION] [API PATH]`
87
+
88
+
This feature is part of the "Bluemix Native API Management" feature and currently supports very powerful API management features like security, rate limiting, and more. For now though we're just using the CLI to expose our action with a REST endpoint. You can read more about this feature here: [API Gateway](https://console.ng.bluemix.net/docs/openwhisk/openwhisk_apigateway.html#openwhisk_apigateway).
89
+
97
90
```bash
98
91
# POST /v1/cat {"name": "Tahoma", "color": "Tabby"}
99
-
wsk api-experimental create -n "Cats API" /v1 /cat post create-cat
92
+
wsk api create -n "Cats API" /v1 /cat post create-cat
100
93
101
94
# GET /v1/cat?id=1
102
-
wsk api-experimental create /v1 /cat get fetch-cat
95
+
wsk api create /v1 /cat get fetch-cat
103
96
```
97
+
In both cases, the CLI will output the URL required to use the API. Make note of those URLs!
104
98
105
99
## Test with `curl` HTTP requests
106
100
Take note of the API URL that is generated from the previous command. Send an http POST and GET request using CuRL to test the actions. Remember to send the required parameters in the body of the request for POST, or as path parameters for GET. OpenWhisk automatically forwards these parameters to the actions we created.
0 commit comments