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 3fd1fa0

Browse files
Update README.md
Simplified code Added web annotation Used new API cli stuff. Removed use of EXPORT since that won't work on Windows. Modified Curl command a bit.
1 parent fed6e66 commit 3fd1fa0

File tree

1 file changed

+15
-23
lines changed

1 file changed

+15
-23
lines changed

‎README.md

Lines changed: 15 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,15 @@ Create a file named `create-cat.js`. This file will define an OpenWhisk action w
1717
function main(params) {
1818

1919
return new Promise(function(resolve, reject) {
20-
console.log(params.name);
21-
console.log(params.color);
2220

2321
if (!params.name) {
24-
console.error('name parameter not set.');
2522
reject({
2623
'error': 'name parameter not set.'
2724
});
28-
return;
2925
} else {
3026
resolve({
31-
statusCode: 201,
3227
id: 1
3328
});
34-
return;
3529
}
3630

3731
});
@@ -44,22 +38,17 @@ Create a file named `fetch-cat.js`. This file will define an OpenWhisk action wr
4438
function main(params) {
4539

4640
return new Promise(function(resolve, reject) {
47-
console.log(params.id);
4841

4942
if (!params.id) {
50-
console.error('id parameter not set.');
5143
reject({
5244
'error': 'id parameter not set.'
5345
});
54-
return;
5546
} else {
5647
resolve({
57-
statusCode: 200,
58-
id: 1,
48+
id: params.id,
5949
name: 'Tahoma',
6050
color: 'Tabby'
6151
});
62-
return;
6352
}
6453

6554
});
@@ -70,9 +59,11 @@ function main(params) {
7059
## Upload actions and test
7160
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]`
7261
```bash
73-
wsk action create create-cat create-cat.js
74-
wsk action create fetch-cat fetch-cat.js
62+
wsk action create create-cat create-cat.js --web true
63+
wsk action create fetch-cat fetch-cat.js --web true
7564
```
65+
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+
7667
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.
7768

7869
```bash
@@ -92,36 +83,37 @@ wsk action invoke \
9283
9384
# 2. Create REST endpoints
9485
## 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+
9790
```bash
9891
# 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
10093

10194
# GET /v1/cat?id=1
102-
wsk api-experimental create /v1 /cat get fetch-cat
95+
wsk api create /v1 /cat get fetch-cat
10396
```
97+
In both cases, the CLI will output the URL required to use the API. Make note of those URLs!
10498

10599
## Test with `curl` HTTP requests
106100
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.
107101

108102
```bash
109-
# Get the REST URL base
110-
export CAT_API_URL=`wsk api-experimental list | tail -1 | awk '{print 5ドル}'`
111103

112104
# POST /v1/cat {"name": "Tahoma", "color": "Tabby"}
113-
curl -X POST -d "{\"name\":\"Tahoma\",\"color\":\"Tabby\"}"$CAT_API_URL
105+
curl -X POST -H 'Content-Type: application/json' -d '{"name":"Tahoma","color":"Tabby"}'<<USE THE URL FROM ABOVE>>
114106
115107
# GET /v1/cat?id=1
116-
curl ${CAT_API_URL}?id=1
108+
curl <<USE THE URL FROM ABOVE>>?id=1
117109
```
118110
119111
# 3. Clean up
120112
## Remove the API mappings and delete the actions
121113
122114
```bash
123115
# Remove API base
124-
wsk api-experimental delete /v1
116+
wsk api delete /v1
125117
126118
# Remove actions
127119
wsk action delete create-cat

0 commit comments

Comments
(0)

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