Skip to content

Commit

Permalink
Updates based on comments
Browse files Browse the repository at this point in the history
  • Loading branch information
underwoodb-sd-ibm committed Jun 22, 2017
1 parent 6a89bb1 commit c681e6f
Show file tree
Hide file tree
Showing 12 changed files with 73 additions and 107 deletions.
12 changes: 6 additions & 6 deletions docs/actions.md
Original file line number Diff line number Diff line change
Expand Up @@ -648,7 +648,7 @@ docker run --rm -it -v "$(pwd):/owexec" openwhisk/swift3action bash

- Copy the source code and prepare to build it
```
cp /owexec/hello.swift /swift3Action/spm-build/main.swift
cp /owexec/hello.swift /swift3Action/spm-build/main.swift
```

```
Expand Down Expand Up @@ -677,16 +677,16 @@ docker run --rm -it -v "$(pwd):/owexec" openwhisk/swift3action bash
exit
```

This has created hello.zip in the same directory as hello.swift.
This has created hello.zip in the same directory as hello.swift.
-Upload it to OpenWhisk with the action name helloSwifty:
```
wsk action update helloSwiftly hello.zip --kind swift:3
```

- To check how much faster it is, run
- To check how much faster it is, run
```
wsk action invoke helloSwiftly --blocking
```
```


The time it took for the action to run is in the "duration" property and compare to the time it takes to run with a compilation step in the hello action.
Expand Down Expand Up @@ -917,13 +917,13 @@ You can list all the actions that you have created using:
wsk action list
```

By default, listed actions will be sorted alphabetically, first by namespaces, then [packages](./packages.md), and finally by action name. To filter your list of actions to just the those within a specific pacakge, you can use:
By default, listed actions will be sorted alphabetically, first by namespaces, then [packages](./packages.md), and finally by action name. To filter your list of actions to just the those within a specific pacakge, you can use:

```
wsk action list [PACKAGE NAME]
```

Side Note: Listing works the same way for actions as it does for [packages](./packages.md), [APIs](./apigateway.md), [triggers and rules](./triggers_rules.md).
*Note:* Listing works the same way for actions as it does for [packages](./packages.md), [APIs](./apigateway.md), [triggers and rules](./triggers_rules.md).

## Deleting actions

Expand Down
30 changes: 15 additions & 15 deletions docs/apigateway.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,18 @@ Follow the instructions in [Configure CLI](./README.md#setting-up-the-openwhisk-
return {payload: `Hello world ${name}`};
}
```

2. Create a web action from the following JavaScript function. For this example, the action is called 'hello'. Make sure to add the flag `--web true`

```
wsk action create hello hello.js --web true
```
```
ok: created action hello
```

3. Create an API with base path `/hello`, path `/world` and method `get` with response type `json`

```
wsk api create /hello /world get hello --response-type json
```
Expand All @@ -42,9 +42,9 @@ Follow the instructions in [Configure CLI](./README.md#setting-up-the-openwhisk-
https://${APIHOST}:9001/api/21ef035/hello/world
```
A new URL is generated exposing the `hello` action via a __GET__ HTTP method.

4. Let's give it a try by sending a HTTP request to the URL.

```
$ curl https://${APIHOST}:9001/api/21ef035/hello/world?name=OpenWhisk
```
Expand All @@ -54,11 +54,11 @@ Follow the instructions in [Configure CLI](./README.md#setting-up-the-openwhisk-
}
```
The web action `hello` was invoked, returning back a JSON object including the parameter `name` sent via query parameter. You can pass parameters to the action via simple query parameters, or via the request body. Web actions allow you to invoke an action in a public way without the OpenWhisk authorization API key.

### Full control over the HTTP response
The `--response-type` flag controls the target URL of the web action to be proxied by the API Gateway. Using `--response-type json` as above returns the full result of the action in JSON format and automatically sets the Content-Type header to `application/json` which enables you to easily get started.

The `--response-type` flag controls the target URL of the web action to be proxied by the API Gateway. Using `--response-type json` as above returns the full result of the action in JSON format and automatically sets the Content-Type header to `application/json` which enables you to easily get started.

Once you get started you want to have full control over the HTTP response properties like `statusCode`, `headers` and return different content types in the `body`. You can do this by using `--response-type http`, this will configure the target URL of the web action with the `http` extension.

You can choose to change the code of the action to comply with the return of web actions with `http` extension or include the action in a sequence passing its result to a new action that transforms the result to be properly formatted for an HTTP response. You can read more about response types and web actions extensions in the [Web Actions](webactions.md) documentation.
Expand All @@ -67,14 +67,14 @@ Follow the instructions in [Configure CLI](./README.md#setting-up-the-openwhisk-
```javascript
function main({name:name='Serverless API'}) {
return {
body: new Buffer(JSON.stringify({payload:`Hello world ${name}`})).toString('base64'),
statusCode:200,
body: new Buffer(JSON.stringify({payload:`Hello world ${name}`})).toString('base64'),
statusCode:200,
headers:{ 'Content-Type': 'application/json'}
};
}
```
Notice that the body needs to be return encoded in `base64` and not a string.

Update the action with the modified result
```
wsk action update hello hello.js --web true
Expand Down Expand Up @@ -149,7 +149,7 @@ Action: putBooks
URL: https://${APIHOST}:9001/api/21ef035/club/books
```

Side Note: APIs will be sorted alphabetically by default, first by Base path, then by Path (relative path), then by Verb. If we need to sort alphabetically by Action name, we can add the `-n` or `--sort-action` flags to do so.
*Note:* APIs will be sorted alphabetically by default, first by Base path, then by Path (relative path), then by Verb. If we need to sort alphabetically by Action name, we can add the `-n` or `--sort-action` flags to do so.

Now just for fun let's add a new book `JavaScript: The Good Parts` with a HTTP __POST__
```
Expand All @@ -172,7 +172,7 @@ curl -X GET https://${APIHOST}:9001/api/21ef035/club/books
```

### Exporting the configuration
Let's export API named `Book Club` into a file that we can use as a base to to re-create the APIs using a file as input.
Let's export API named `Book Club` into a file that we can use as a base to to re-create the APIs using a file as input.
```
wsk api get "Book Club" > club-swagger.json
```
Expand Down
22 changes: 11 additions & 11 deletions docs/packages.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,17 @@ Several packages are registered with OpenWhisk. You can get a list of packages i
```
```
packages
/whisk.system/alarms shared
/whisk.system/cloudant shared
/whisk.system/github shared
/whisk.system/pushnotifications shared
/whisk.system/samples shared
/whisk.system/slack shared
/whisk.system/system shared
/whisk.system/utils shared
/whisk.system/watson shared
/whisk.system/weather shared
/whisk.system/websocket shared
/whisk.system/alarms shared
/whisk.system/cloudant shared
/whisk.system/github shared
/whisk.system/pushnotifications shared
/whisk.system/samples shared
/whisk.system/slack shared
/whisk.system/system shared
/whisk.system/utils shared
/whisk.system/watson shared
/whisk.system/weather shared
/whisk.system/websocket shared
```

2. Get a list of entities in the `/whisk.system/cloudant` package.
Expand Down
2 changes: 1 addition & 1 deletion docs/triggers_rules.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ As an example, create a trigger to send user location updates, and manually fire
ok: created trigger locationUpdate
```

2. Check that you created the trigger by listing the set of triggers. (Side note: triggers and rules will be listed alphabetically when using the `list` command.)
2. Check that you created the trigger by listing the set of triggers.

```
$ wsk trigger list
Expand Down
56 changes: 10 additions & 46 deletions tests/src/test/scala/apigw/healthtests/ApiGwEndToEndTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -87,34 +87,28 @@ class ApiGwEndToEndTests
try {
//Create Actions for apiexperimentals
val file = TestUtils.getTestActionFilename(s"echo-web-http.js")
println("Create Action: " + actionName1)
assetHelper.withCleaner(wsk.action, actionName1) {
(action, name) => action.create(name, artifact = Some(file), expectedExitCode = SUCCESS_EXIT, web = Some("true"))
}
println("Create Action: " + actionName2)
assetHelper.withCleaner(wsk.action, actionName2) {
(action, name) => action.create(name, artifact = Some(file), expectedExitCode = SUCCESS_EXIT, web = Some("true"))
}
println("Create Action: " + actionName3)
assetHelper.withCleaner(wsk.action, actionName3) {
(action, name) => action.create(name, artifact = Some(file), expectedExitCode = SUCCESS_EXIT, web = Some("true"))
}
//Create apiexperimentals
println("Create api-experimental: Base Path " + base2)
// Create apiexperimentals
wsk.apiexperimental.create(
basepath = Some(base2),
relpath = Some("/relPath1"),
operation = Some("get"),
action = Some(actionName2)
)
println("Create api-experimental: Base Path " + base1)
wsk.apiexperimental.create(
basepath = Some(base1),
relpath = Some("/relPath2"),
operation = Some("delete"),
action = Some(actionName1)
)
println("Create api-experimental: Base Path " + base3)
wsk.apiexperimental.create(
basepath = Some(base3),
relpath = Some("/relPath3"),
Expand All @@ -131,11 +125,8 @@ class ApiGwEndToEndTests
scalaSorted.toString shouldEqual listFull.toString
} finally {
//Clean up apiexperimentals
println("Delete api-experimental: Base Path " + base1)
wsk.apiexperimental.delete(base1, expectedExitCode = DONTCARE_EXIT)
println("Delete api-experimental: Base Path " + base2)
wsk.apiexperimental.delete(base2, expectedExitCode = DONTCARE_EXIT)
println("Delete api-experimental: Base Path " + base3)
wsk.apiexperimental.delete(base3, expectedExitCode = DONTCARE_EXIT)
}
}
Expand All @@ -151,36 +142,30 @@ class ApiGwEndToEndTests
val base3 = "/BaseTestPath3"

try {
//Create Actions for api-experimentals
// Create Actions for api-experimentals
val file = TestUtils.getTestActionFilename(s"echo-web-http.js")
println("Create Action: " + actionName1)
assetHelper.withCleaner(wsk.action, actionName1) {
(action, name) => action.create(name, artifact = Some(file), expectedExitCode = SUCCESS_EXIT, web = Some("true"))
}
println("Create Action: " + actionName2)
assetHelper.withCleaner(wsk.action, actionName2) {
(action, name) => action.create(name, artifact = Some(file), expectedExitCode = SUCCESS_EXIT, web = Some("true"))
}
println("Create Action: " + actionName3)
assetHelper.withCleaner(wsk.action, actionName3) {
(action, name) => action.create(name, artifact = Some(file), expectedExitCode = SUCCESS_EXIT, web = Some("true"))
}
//Create api-experimentals
println("Create api-experimental: Base Path " + base2)
// Create api-experimentals
wsk.apiexperimental.create(
basepath = Some(base2),
relpath = Some("/relPath1"),
operation = Some("get"),
action = Some(actionName2)
)
println("Create apiexperimental: Base Path " + base1)
wsk.apiexperimental.create(
basepath = Some(base1),
relpath = Some("/relPath2"),
operation = Some("delete"),
action = Some(actionName1)
)
println("Create apiexperimental: Base Path " + base3)
wsk.apiexperimental.create(
basepath = Some(base3),
relpath = Some("/relPath3"),
Expand All @@ -196,12 +181,9 @@ class ApiGwEndToEndTests
scalaSorted.toString shouldEqual list.toString
scalaSorted.toString shouldEqual listFull.toString
} finally {
//Clean up apiexperimentals
println("Delete apiexperimental: Base Path " + base1)
// Clean up apiexperimentals
wsk.apiexperimental.delete(base1, expectedExitCode = DONTCARE_EXIT)
println("Delete apiexperimental: Base Path " + base2)
wsk.apiexperimental.delete(base2, expectedExitCode = DONTCARE_EXIT)
println("Delete apiexperimental: Base Path " + base3)
wsk.apiexperimental.delete(base3, expectedExitCode = DONTCARE_EXIT)
}
}
Expand Down Expand Up @@ -287,38 +269,32 @@ class ApiGwEndToEndTests
val base3 = "/BaseTestPath3"

try {
//Create Actions for Apis
// Create Actions for Apis
val file = TestUtils.getTestActionFilename(s"echo-web-http.js")
println("Create Action: " + actionName1)
assetHelper.withCleaner(wsk.action, actionName1) {
(action, name) => action.create(name, artifact = Some(file), expectedExitCode = SUCCESS_EXIT, web = Some("true"))
}
println("Create Action: " + actionName2)
assetHelper.withCleaner(wsk.action, actionName2) {
(action, name) => action.create(name, artifact = Some(file), expectedExitCode = SUCCESS_EXIT, web = Some("true"))
}
println("Create Action: " + actionName3)
assetHelper.withCleaner(wsk.action, actionName3) {
(action, name) => action.create(name, artifact = Some(file), expectedExitCode = SUCCESS_EXIT, web = Some("true"))
}
//Create Apis
println("Create API: Base Path " + base2)
// Create Apis
wsk.api.create(
basepath = Some(base2),
relpath = Some("/relPath1"),
operation = Some("get"),
action = Some(actionName2),
cliCfgFile = Some(cliWskPropsFile.getCanonicalPath())
)
println("Create API: Base Path " + base1)
wsk.api.create(
basepath = Some(base1),
relpath = Some("/relPath2"),
operation = Some("delete"),
action = Some(actionName1),
cliCfgFile = Some(cliWskPropsFile.getCanonicalPath())
)
println("Create API: Base Path " + base3)
wsk.api.create(
basepath = Some(base3),
relpath = Some("/relPath3"),
Expand All @@ -335,12 +311,9 @@ class ApiGwEndToEndTests
scalaSorted.toString shouldEqual list.toString
scalaSorted.toString shouldEqual listFull.toString
} finally {
//Clean up Apis
println("Delete API: Base Path " + base1)
// Clean up Apis
wsk.api.delete(base1, expectedExitCode = DONTCARE_EXIT, cliCfgFile = Some(cliWskPropsFile.getCanonicalPath()))
println("Delete API: Base Path " + base2)
wsk.api.delete(base2, expectedExitCode = DONTCARE_EXIT, cliCfgFile = Some(cliWskPropsFile.getCanonicalPath()))
println("Delete API: Base Path " + base3)
wsk.api.delete(base3, expectedExitCode = DONTCARE_EXIT, cliCfgFile = Some(cliWskPropsFile.getCanonicalPath()))
}
}
Expand All @@ -356,38 +329,32 @@ class ApiGwEndToEndTests
val base3 = "/BaseTestPath3"

try {
//Create Actions for Apis
// Create Actions for Apis
val file = TestUtils.getTestActionFilename(s"echo-web-http.js")
println("Create Action: " + actionName1)
assetHelper.withCleaner(wsk.action, actionName1) {
(action, name) => action.create(name, artifact = Some(file), expectedExitCode = SUCCESS_EXIT, web = Some("true"))
}
println("Create Action: " + actionName2)
assetHelper.withCleaner(wsk.action, actionName2) {
(action, name) => action.create(name, artifact = Some(file), expectedExitCode = SUCCESS_EXIT, web = Some("true"))
}
println("Create Action: " + actionName3)
assetHelper.withCleaner(wsk.action, actionName3) {
(action, name) => action.create(name, artifact = Some(file), expectedExitCode = SUCCESS_EXIT, web = Some("true"))
}
//Create Apis
println("Create API: Base Path " + base2)
// Create Apis
wsk.api.create(
basepath = Some(base2),
relpath = Some("/relPath1"),
operation = Some("get"),
action = Some(actionName2),
cliCfgFile = Some(cliWskPropsFile.getCanonicalPath())
)
println("Create API: Base Path " + base1)
wsk.api.create(
basepath = Some(base1),
relpath = Some("/relPath2"),
operation = Some("delete"),
action = Some(actionName1),
cliCfgFile = Some(cliWskPropsFile.getCanonicalPath())
)
println("Create API: Base Path " + base3)
wsk.api.create(
basepath = Some(base3),
relpath = Some("/relPath3"),
Expand All @@ -406,12 +373,9 @@ class ApiGwEndToEndTests
scalaSorted.toString shouldEqual list.toString
scalaSorted.toString shouldEqual listFull.toString
} finally {
//Clean up Apis
println("Delete API: Base Path " + base1)
// Clean up Apis
wsk.api.delete(base1, expectedExitCode = DONTCARE_EXIT, cliCfgFile = Some(cliWskPropsFile.getCanonicalPath()))
println("Delete API: Base Path " + base2)
wsk.api.delete(base2, expectedExitCode = DONTCARE_EXIT, cliCfgFile = Some(cliWskPropsFile.getCanonicalPath()))
println("Delete API: Base Path " + base3)
wsk.api.delete(base3, expectedExitCode = DONTCARE_EXIT, cliCfgFile = Some(cliWskPropsFile.getCanonicalPath()))
}
}
Expand Down
Loading

0 comments on commit c681e6f

Please sign in to comment.