cli ๋ฅผ ํ†ตํ•ด ๋งŒ๋“  action, sequence ์— endpoint๋ฅผ ์ƒ์„ฑ ํ•ด์„œ http request๋กœ db ์ฝ๊ณ  ์“ฐ๊ธฐ๋ฅผ ํ•ด๋ณด๊ฒ ๋‹ค.
(๊ถ๊ทน์ ์œผ๋กœ๋Š” REST API๋ฅผ ๋งŒ๋“ค์–ด http request๋กœ CRUD๋ฅผ ๊ตฌํ˜„ ํ•˜๊ณ ์ž ํ•œ๋‹ค.)

endpoint์—๋Š” web action์„ enable ํ•˜๋Š” ๋ฐฉ๋ฒ•๊ณผ api gateway๋ฅผ ์ฃผ๋Š” ๋ฐฉ๋ฒ•์ด ์žˆ๋‹ค.
web http access ๋ฅผ enable ํ•˜๋Š” flag๋Š” –web yes๋ฅผ ์ฃผ๋ฉด ๋œ๋‹ค.
์šฐ๋ฆฌ๊ฐ€ ์ด์ „ lab์—์„œ ๋งŒ๋“ค์—ˆ๋˜ write-to-cloudant ์— web action์„ enable ํ•ด๋ณด์ž.

1. endpoint ์ƒ์„ฑ
$bx wsk action update write-to-cloudant –web true

web action ์ด true ์ธ action์€ ์•„๋ž˜์™€ ๊ฐ™์€ ๊ทœ์น™์œผ๋กœ http ์ ‘๊ทผ ๊ฐ€๋Šฅํ•˜๋‹ค.
https;//{APIHOST}/api/v1/web/{ACTION NAME}

๊ทธ๋Ÿฌ๋ฏ€๋กœ ์•„๋ž˜์™€ ๊ฐ™์€ endpoint๊ฐ€ ๊ฐ€๋Šฅํ•˜๋‹ค.
https://openwhisk.ng.bluemix.net/api/v1/web/yjh@kr.ibm.com_korea/default/write-to-cloudant

2. endpoint ํ™•์ธ
๋ช…๋ น์–ด๋ฅผ ํ†ตํ•ด ํ™•์ธ ํ•  ์ˆ˜๋„ ์žˆ๋‹ค.
$bx wsk action get write-to-cloudant –url

3. Test endpoint
http request๋ฅผ ํ†ตํ•ด action์„ ์ˆ˜ํ–‰ ํ•ด๋ณด์ž
curl ๋˜๋Š” httpie ๋˜๋Š” ๋ธŒ๋ผ์šฐ์ €์— ์ง์ ‘ url์„ ์ž…๋ ฅ ํ•ด๋ณด์ž. ์ž˜ ์ž…๋ ฅ ๋˜๋Š”์ง€ polling์„ ์ผœ๋‘๊ณ  ํ•ด๋ณด์ž.
https://openwhisk.ng.bluemix.net/api/v1/web/yjh@kr.ibm.com_korea/default/write-to-cloudant?docid=test3

์ž˜ ์ž…๋ ฅ ๋œ ๊ฒƒ์„ ํ™•์ธ ํ•  ์ˆ˜ ์žˆ๋‹ค.
์•„๋ž˜์™€ ๊ฐ™์ด ์—ฌ๋Ÿฌ๊ฐ€์ง€ ๋ฐฉ๋ฒ•์œผ๋กœ data insert ๊ฒฐ๊ณผ๋ฅผ ํ™•์ธ ํ•  ์ˆ˜ ์žˆ๋‹ค.

a. activation log $bx wsk activation poll b. cloudant web gui c. cloudant read command $bx wsk action invoke /yjh@kr.ibm.com_korea/Bluemix_Cloudant-Serverless_Credentials-1/read –blocking –result –param dbname cats –param docid test3

4. API gateway ์ด์šฉํ•˜๊ธฐ ์ผ๋ฐ˜์ ์œผ๋กœ data insert๋Š” http์˜ get method๋กœ ๊ตฌํ˜„ํ•˜์ง„ ์•Š๋Š”๋‹ค. post ๋กœ ๊ตฌํ˜„ ํ•˜๋Š”๊ฒŒ ๋งž๋‹ค. ๋˜ํ•œ ๋‹จ์ˆœํžˆ web action ์„ true๋ผ ํ•˜์—ฌ http request๋ฅผ ํ•˜๋Š”๊ฒƒ ๋ณด๋‹จ api gateway๋ฅผ ์ด์šฉํ•˜์—ฌ action์„ ์ˆ˜ํ–‰ ํ•˜๋Š”๊ฒŒ ์ข‹๋‹ค. (API gateway๋ฅผ ์ด์šฉํ•˜๋ ค๋ฉด ๊ธฐ๋ณธ์ ์œผ๋กœ action์˜ bx wsk action invoke ๋ฅผ ํ•ด์•ผ ํ•œ๋‹ค.)

API gateway๋ฅผ ์ด์šฉํ–ˆ์„๋•Œ์˜ ์žฅ์ 

โ€ขSecurity
์›์น˜์•Š๋Š” ์ ‘๊ทผ์„ ๋ง‰์„ ์ˆ˜ ์žˆ๋‹ค. authentication์„ ํ†ตํ•ด access ์ œ์–ด๊ฐ€ ๊ฐ€๋Šฅํ•˜๋‹ค.
API key,API secret, and OAuth validation์ด ๊ฐ€๋Šฅํ•˜๋‹ค.
Google,Facebook, and GitHub๊ฐ€ ์ œ๊ณตํ•˜๋Š” OAuth ๋ฅผ ์—ฐ๋™ํ•˜์—ฌ ์“ธ ์ˆ˜ ์žˆ๋‹ค.

ย โ€ข Rate limiting
api key๋ณ„๋กœ ํ˜ธ์ถœ ํšŒ์ˆ˜๋ฅผ ์ œํ•œ ํ•  ์ˆ˜ ์žˆ๋‹ค. api๋ฅผ publicํ•˜๊ฒŒ ์‚ฌ์šฉํ•  ๊ฒฝ์šฐ ๋งค์šฐ ์œ ์šฉํ•˜๊ฒŒ ์“ฐ์ผ ๊ธฐ๋Šฅ์ด๋‹ค.
ย โ€ขAnalytics
api callย ์„ ๋ถ„์„ํ•˜๊ธฐ ์ข‹๋‹ค. ๋ˆ„๊ฐ€ ๋ช‡๋ฒˆ ์–ด๋–คํŒŒ๋ผ๋ฏธํ„ฐ๋กœ call์„ ํ–ˆ๋Š”์ง€ ์ถ”์ ์ด ๊ฐ€๋Šฅํ•˜๋‹ค.

๊ธฐ๋ณธ์ ์œผ๋กœ ์•„๋ž˜์™€ ๊ฐ™์€ ์ •๋ณด๋ฅผ ํ™•์ธ ํ•  ์ˆ˜ ์žˆ๋‹ค.
- ํŠน์ • ์‹œ๊ฐ„๋™์•ˆ api ํ˜ธ์ถœ ์ˆ˜.
- ๋ถ„๋‹น API ํ˜ธ์ถœ์ˆ˜.
- ์ตœ๊ทผ 100 ๊ฐœ์‘๋‹ต.

โ€ขSharing
์†์‰ฝ๊ฒŒ endpoint๋ฅผ ๊ณต์œ  ํ•  ์ˆ˜ ์žˆ๋‹ค.

โ€ขTesting
API Explorer
๋ฅผ ์ด์šฉํ•ด ์†์‰ฝ๊ฒŒ ํ…Œ์ŠคํŠธ ํ•  ์ˆ˜ ์žˆ๋‹ค.

์ฐธ์กฐ: Developing serverless backends with OpenWhisk and API Gateway integrations]

5. API gateway๋ฅผ ์ด์šฉํ•œ endpoint ์ƒ์„ฑ
์•„๋ž˜์™€ ๊ฐ™์ด api gateway๋ฅผ ํ†ตํ•œ endpoint๋ฅผ ๋งŒ๋“ค ์ˆ˜ ์žˆ๋‹ค.
action์— api endpoint mapping
$bx wsk api create /Wcloudant GET write-to-cloudant

์•„๋ž˜์™€ ๊ฐ™์€ ๊ฒฐ๊ณผ๋ฅผ ์–ป์„ ์ˆ˜ ์žˆ๋‹ค.

์•„๋ž˜ url๋กœ api action์„ ์‹คํ–‰ ํ•  ์ˆ˜ ์žˆ๋‹ค.
https://service.us.apiconnect.ibmcloud.com/gws/apigateway/api/7bbe0aa3d0ab81a7ad43ddc9c03db9e0533d077842fb3645c22ec43323d59363/Wcloudant

์ด์ œ api gateway๋ฅผ ํ™œ์šฉํ•œ CRUD๋ฅผ ๊ตฌํ˜„ํ•ด ๋ณด์ž.
(๋ชจ๋“  ๊ณผ์ •์€ web gui๋กœ๋„ ํ•  ์ˆ˜ ์žˆ๋‹ค. web gui๋กœ ๊ตฌํ˜„ํ•˜๋Š” ๋ฐฉ๋ฒ•์€ย  ์„ค๋ช…ํ•˜์ง„ ์•Š๊ฒ ๋‹ค. web gui๋Š” ๋งค์šฐ ์ง๊ด€์ ์œผ๋กœ design๋˜์–ด ์žˆ๊ธฐ์— ์•„๋ž˜ ๊ณผ์ •์„ ์ดํ•ด ํ•œ๋‹ค๋ฉด ์„ค๋ช… ์—†์ด๋„ ์‚ฌ์šฉ ๊ฐ€๋Šฅํ•  ๊ฒƒ์ด๋‹ค.)

[Go to HTTP API CRUD ์‹ค์Šต]

ํ† ๋ก  ์ฐธ๊ฐ€

์ด๋ฉ”์ผ์€ ๊ณต๊ฐœ๋˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค. ํ•„์ˆ˜ ์ž…๋ ฅ์ฐฝ์€ * ๋กœ ํ‘œ์‹œ๋˜์–ด ์žˆ์Šต๋‹ˆ๋‹ค