# ハンズオンマテリアル # 目的 コピー&ペースト作業など複雑な処理を行う際は必要に応じてこちらのシートを活用させていただきます。 # RDP (Remote Destop)のCredential | ID | Password | | -------- | -------- | | workshop | fCjnB*EEU4F!S36! | # RDPアクセス後の設定 * デフォルトブラウザをIEからChromeへ変更する ![](https://i.imgur.com/ti7JCHc.png) # Anypoint Platform https://anypoint.mulesoft.com/home * Anypoint Platformへログイン後、Business GroupをYANASE Workshopになっているか確認する。異なる場合には変更する。 ![](https://i.imgur.com/R81KXxy.png) # ハンズオンステップ ## 自分の API 仕様を作成する * API Title (xxは番号:flight-system-no) ``` flight-system-xx ``` > XX - 01 * API仕様の編集(既存のテキストを削除して、以下をコピー&ペースト) ``` #%RAML 1.0 title: flight-system mediaType: - application/json /americanflights: get: securedBy: [] responses: "200": body: application/json: type: flightdata items: type: object /flights: get: displayName: get all flight responses: "200": body: application/json: type: flightdata securedBy: [] /qantasflights: get: responses: "200": body: application/json: type: flightdata items: type: object securedBy: [] /americanflight/{flightcode}: get: responses: "200": body: application/json: type: flightdata items: type: object securedBy: [] uriParameters: flightcode: type: string /flights/from-to: get: description: From-Toを指定した queryParameters: fromairport: example: Example type: string toairport: example: Example type: string responses: "200": body: application/json: type: flightdata items: type: object securedBy: [] /flights/{toairport}: get: queryParameters: airline?: example: Example type: string responses: "200": body: application/json: type: flightdata items: type: object securedBy: [] uriParameters: toairport: type: string version: "1.0" securedBy: [] protocols: - HTTPS - HTTP types: flightdata: items: properties: flightcode?: example: Example type: string toairport?: example: Example type: string fromairport?: example: Example type: string takeoffdate?: example: Example type: string price?: example: 1 type: number format: int airplane?: example: Example type: string airline?: example: Example type: string ``` ## インポートした API 仕様で新しい Studio プロジェクトを作成する   (API仕様のインポートはHands-on時に説明します) * Project Name (xxはご自身の番号) ``` flight-system-xx ``` ## API を設定する データベースコネクションを設定する ![image alt](https://i.imgur.com/Ls8Ob9T.png) #### DataBase (MySQL)のCredential > Connection : MySQL Connection (プルダウンから選択) > Required Libraries : *Configure*をクリック -> リストから*Add recomended libraries*を選択 > Host : vkh7buea61avxg07.cbetxkdyhwsb.us-east-1.rds.amazonaws.com > Uaer : cvnp0q17xfehaze6 > Password : aevgjez152slmwn2 > Port : 3306 > Database : ahiv2kiz64e4w5g2 このフローを作成する ![](https://i.imgur.com/sARDPYu.png) * Selectに設定するSQL ``` select * from american ``` * Transform Messageのマッピング ![image alt](https://i.imgur.com/1BgSeVq.png) * Flight codeの編集 ``` flightcode: (payload01.code1 default "") ++ "-" ++ (payload01.code2 default "") ``` ![image alt](https://i.imgur.com/RvyXZVw.png) ## API をテストする * Postman初回起動時には、Sign in画面が表示されるがSkipする > Postmanの初回起動時画面 ![](https://imgur.com/rhZ0316.png) * PostmanのRequest URL ``` http://localhost:8081/api/americanflights ``` ## API を CloudHub にデプロイする * Application Name (xxはご自身の番号) ``` flight-system-xx ``` デプロイ成功時の画面 ![image alt](https://i.imgur.com/CgSNznA.png) * デプロイしたアプリケーションの稼動確認 (Postman、xxはイニシャル) http://flight-system-xx.us-e2.cloudhub.io/api/americanflights ## API をAPI Managerに追加 * Proxy application name (xxはご自身の番号) ``` flight-system-proxy-xx ``` * Implementation URI (xxはご自身の番号) ``` http://flight-system-xx.us-e2.cloudhub.io/api ``` ## API プロキシの作成と設定 * Add consumer endpoint (xxはご自身の番号) ``` http://flight-system-proxy-xx.us-e2.cloudhub.io/ ``` ## レート制限ポリシーを追加する * Label ``` Rate-limiting policy ``` * PostmanのRequest URL(xxはご自身の番号) ``` http://flight-system-proxy-xx.us-e2.cloudhub.io/americanflights ``` # Process APIを作成し上で作成したAPIを呼び出す ## API 仕様を作成する * API Title (xxはご自身の番号) ``` flight-info-papi-xx ``` ## インポートした API 仕様でProcess API用の新しい Studio プロジェクトを作成する   (API仕様のインポートはHands-on時に説明します) * Project Name (xxはご自身の番号) ``` flight-info-papi-xx ``` ## API を設定する このフローを作成する。 処理はパラメータとしてamericanを受け取ったらアメリカン航空の情報を取得し、それ以外なら全件を取得する。 (ただし、全件取得処理は作成していないため空のレスポンスが戻ってくる) ![link text](https://i.imgur.com/C4X8rdt.png) * 先ほど作成したフライト情報を取得するSystem APIをExchangeで探し、Add to Projectで追加する ![image alt](https://i.imgur.com/DHk8eTa.png) * ChoiceコンポーネントをDrag&Dropで持ってきて、Whenにスコープを当てる ![image alt](https://i.imgur.com/lpK7vGP.png) * Expressionの関数(*fx*)ボタンを押下し、以下の条件分を貼り付ける。 ``` attributes.queryParams.airlinename == "american" ``` * flight-systemコンポーネントから、WhenにGet americanflightsを、elseにget all flightをDrag&Drop ![image alt](https://i.imgur.com/HqTCjeD.png) * flight-systemのConnector configurationを以下のように設定する (設定するのは上記で作成した、Proxy経由のflight-system API) ![image alt](https://i.imgur.com/ChPjsIY.png) > Host : flight-system-proxy-xx.us-e2.cloudhub.io (xxはご自身の番号) > port : 80 > protocol : HTTP ***※ basePathとResponse timeoutはデフォルトのまま***