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

Browse files
committed
Update README
1 parent f30c79a commit 2bf9709

File tree

1 file changed

+20
-13
lines changed

1 file changed

+20
-13
lines changed

‎README.md

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# OpenWhisk Building Block - HTTP REST Trigger
1+
# OpenWhisk Building Block - HTTP REST API Trigger
22
Create REST API mappings with Apache OpenWhisk on IBM Bluemix. This tutorial takes less than 5 minutes to complete. After this, move on to more complex serverless applications such as those tagged [_openwhisk-hands-on-demo_](https://github.com/search?q=topic%3Aopenwhisk-hands-on-demo+org%3AIBM&type=Repositories).
33

44
![Sample Architecture](https://openwhisk-ui-prod.cdn.us-south.s-bluemix.net/openwhisk/ngow-public/img/getting-started-serverless-api.svg)
@@ -12,7 +12,10 @@ This example provides two REST endpoints, HTTP `POST` and `GET` methods that are
1212
4. [Clean up](#3-clean-up)
1313

1414
# 1. Create OpenWhisk actions
15-
Create a file named `create-cat.js`. This file will define an OpenWhisk action written as a JavaScript function. It checks for the required parameters(`name` and `color`) and returns 201, or an error if either parameter is missing. This example is simplified, and does not connect to a backend datastore. For a more complicated example, check out this [REST API example](https://github.com/IBM/openwhisk-serverless-apis).
15+
## Create an action to create a cat entity
16+
Create a file named `create-cat.js`. This file will define an OpenWhisk action written as a JavaScript function. It checks for the required parameters(`name` and `color`) and returns a unique identifier for the cat, or an error if either parameter is missing.
17+
> **Note**: This example is simplified, and does not connect to a backend datastore. For a more sophisticated example, check out this [REST API example](https://github.com/IBM/openwhisk-serverless-apis).
18+
1619
```javascript
1720
function main(params) {
1821

@@ -33,7 +36,10 @@ function main(params) {
3336
}
3437
```
3538

36-
Create a file named `fetch-cat.js`. This file will define an OpenWhisk action written as a JavaScript function. It checks for the required parameter(`id`) and returns Tahoma, the tabby colored cat. Again, for the purpose of this simplified demo we always return Tahoma the cat, rather than connecting to a backend datastore.
39+
## Create an action to return a cat entity
40+
Create a file named `fetch-cat.js`. This file will define an OpenWhisk action written as a JavaScript function. It checks for the required parameter(`id`) and returns Tahoma, the tabby colored cat.
41+
> **Note**: Again, for the purpose of this simplified demo we always return Tahoma the cat, rather than connecting to a backend datastore.
42+
3743
```javascript
3844
function main(params) {
3945

@@ -56,14 +62,14 @@ function main(params) {
5662
}
5763
```
5864

59-
## Upload actions and test
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]`
65+
## Upload the actions
66+
The next step will be to create OpenWhisk actions from the JavaScript functions that we just created. We also add the `--web true` flag, to annotate these actions as "Web Actions". This will be necessary later when we add REST endpoints.
6167
```bash
6268
wsk action create create-cat create-cat.js --web true
6369
wsk action create fetch-cat fetch-cat.js --web true
6470
```
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.
6671

72+
## Unit test the actions
6773
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.
6874

6975
```bash
@@ -83,23 +89,24 @@ wsk action invoke \
8389
8490
# 2. Create REST endpoints
8591
## Create POST and GET REST mappings for `/v1/cat` endpoint
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]`
92+
Now that we have our OpenWhisk actions created, we will expose our OpenWhisk actions through the Bluemix API Gateway. To do this we will use: `wsk api create $BASE_PATH $API_PATH $API_VERB $ACTION`
8793

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).
94+
This feature is part of the [Bluemix Native API Management](https://console.ng.bluemix.net/docs/openwhisk/openwhisk_apigateway.html#openwhisk_apigateway) service 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 public REST endpoint.
8995

9096
```bash
97+
# Send along credentials with the command or provide them interactively
9198
wsk bluemix login --user $YOUR_BLUEMIX_USERNAME --password $YOUR_BLUEMIX_PASSWORD
9299

93-
# POST /v1/cat {"name": "Tahoma", "color": "Tabby"}
100+
# Exposes POST /v1/cat {"name": "Tahoma", "color": "Tabby"}
94101
wsk api create -n "Cats API" /v1 /cat post create-cat
95102

96-
# GET /v1/cat?id=1
103+
# Exposes /v1/cat?id=1
97104
wsk api create /v1 /cat get fetch-cat
98105
```
99-
In both cases, the CLI will output the URL required to use the API. Make note of those URLs!
106+
In both cases, the CLI will output the URL required to use the API. Make note of it for the next section.
100107

101108
## Test with `curl` HTTP requests
102-
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.
109+
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.
103110

104111
```bash
105112
# POST /v1/cat {"name": "Tahoma", "color": "Tabby"}
@@ -113,7 +120,7 @@ curl $THE_URL_FROM_ABOVE?id=1
113120
## Remove the API mappings and delete the actions
114121

115122
```bash
116-
# Remove API base
123+
# Remove API base which removes all the mappings
117124
wsk api delete /v1
118125

119126
# Remove actions

0 commit comments

Comments
(0)

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