0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

OpenWhiskを使い簡単な利用の仕方を確認してみる

Posted at

目的

構築した検証用環境を用い、WebUI上でのリソース登録、登録リソースのリモート呼び出し、リモートからのリソース登録などについて、簡単なサンプルコードを用い動作確認していきたいと思います。

Playground(WebUI)からの公開(Publish)

WebUIからGo言語で作成されたサンプルコードを公開していきます。ブラウザでPlygroundを開き、Publishボタンを押下します。押下する左上の「URL」が、「editable, private]から「Readonly, public at http://xxxx」に更新されました。

Go Sample Code
Go Sample Code Publish

URL: Readonly, public at http://192.168.11.55:13233/api/v1/web/whisk.system/user283538/sampleGo

公開されたサービスを呼び出してみる

引数なしでCLIにて対象サービスを呼び出してみます。引数nameを指定していないためコード固定のstrangerの文字列がレスポンスに現れていることを確認できました。

$ curl http://192.168.11.55:13233/api/v1/web/whisk.system/user283538/sampleGo
Hello, stranger!$ 

変数付与したGETメソッドによる呼び出し

では、次に引数nameにGolangを設定しGETメソッドを用いリクエストしてみます。想定通りリクエストパラメータを理解しレスポンスを作成してくれている様です。

$ curl http://192.168.11.55:13233/api/v1/web/whisk.system/user283538/sampleGo?name=Golang
Hello, Golang!$ 

変数付与したPOSTメソッドによる呼び出し

次に、リクエストをjson形式で与えてみます。明示的にヘッダーにjsonを指定しないとエラーになりますね。指定して再実行すると問題なく処理されている様です。

$ curl -X POST http://192.168.11.55:13233/api/v1/web/whisk.system/user283538/sampleGo -d '{"name": "Golang2"}'
{"code":"mCfNUwgfLOEVL0WIZqYXBqXXXLOVEiftiOyE","error":"Illegal query: Invalid input ' ', expected '+', '=', query-char, 'EOI', '&' or pct-encoded (line 1, column 9): {\"name\": \"Golang2\"}\n        ^"}$
$ curl -X POST http://192.168.11.55:13233/api/v1/web/whisk.system/user283538/sampleGo -d '{"name": "Golang2"}' -H "Content-Type: application/json"
Hello, Golang2!$ 

ここまでは割と順調に進めらている感じがします。次は、CLIでサービスを作成してみましょう。

CLIによるサービスの作成

hello.jsというJavaScriptで作成したファイルを準備し公式ドキュメントに従い実行した所、以下エラーとなりうまくいかなかったので今回はここで終了としたいと思います。

$ wsk action create myAction hello.js 
error: Unable to create action 'myAction': Unable to create HTTP request for PUT 'actions/myAction?overwrite=false': Unable to add the HTTP authentication header: Authorization key is not configured (--auth is required)
Run 'wsk --help' for usage.
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?