Last active
December 27, 2015 18:01
-
-
Save masato/0c8a2dc03a70258fe9cb to your computer and use it in GitHub Desktop.
Webhook as a ServiceでIoTのserverlessなバックエンド考える - Part 2: Webtask.ioのHello world ref: http://qiita.com/masato/items/5689238a4d90cfd8a307
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"default": { | |
"url": "https://webtask.it.auth0.com", | |
"container": "{アカウントのコンテナ名}", | |
"token": "{アカウントのwebtask token}" | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ sudo npm install wt-cli -g |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ wt init xxx@gmail.com | |
Please enter the verification code we sent to xxx@gmail.com below. | |
Verification code: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ echo $RESTRICTED_TOKEN | |
eyJhxxx |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ curl -X POST \ | |
"https://webtask.it.auth0.com/api/run/{アカウントのコンテナ名}?name=Masato&key=eyJhxxx" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"Hello, Masato" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Welcome to webtasks! Create your first one as follows: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ echo "module.exports = function (cb) { cb(null, 'Hello'); }" > hello.js | |
$ wt create hello.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Run your new webtask like so: | |
$ curl https://webtask.it.auth0.com/api/run/{アカウントのコンテナ名}/hello?webtask_no_cache=1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"Hello" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
HTTPS POST /api/tokens/issue | |
Content-Type: application/json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export RESTRICTED_TOKEN=$(curl -s https://webtask.it.auth0.com/api/tokens/issue -H "Authorization: Bearer $RESTRICTED_TOKEN" -H "Content-Type: application/json" --data-binary '{"url":"http://bit.ly/18L4CmA"}') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
return function (context, cb) { | |
cb(null, "Hello, " + context.data.name); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment