Top Banner
Google Cloud Endpoints with Dartlang
51

Dart flightschool cloudendpoint with dart

May 22, 2015

Download

Documents

Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Dart flightschool cloudendpoint with dart

Google Cloud Endpointswith

Dartlang

Page 2: Dart flightschool cloudendpoint with dart

誰?

Page 3: Dart flightschool cloudendpoint with dart

大橋啓介

と申します

Page 4: Dart flightschool cloudendpoint with dart

@soundTricker318http://goo.gl/ZpUOs

Page 5: Dart flightschool cloudendpoint with dart

どこの

人?

Page 6: Dart flightschool cloudendpoint with dart

http://www.bfts.co.jp

Page 7: Dart flightschool cloudendpoint with dart

何やってる?

Page 8: Dart flightschool cloudendpoint with dart
Page 9: Dart flightschool cloudendpoint with dart

https://www.flickr.com/photos/centralasian/ (CC)

電車プログラマ

Page 10: Dart flightschool cloudendpoint with dart

ぼくと

altjs

Page 11: Dart flightschool cloudendpoint with dart

GWT

GWT Bootstrap※コミッター

CoffeeScript

Page 12: Dart flightschool cloudendpoint with dart

←Javaで書ける夢を見た

←ナマの JSツライ※Javascript → Javaのポーティング

←漠然とした不安感※今のところココに落ち着いてる

Page 13: Dart flightschool cloudendpoint with dart

話す事

Page 14: Dart flightschool cloudendpoint with dart

Google Cloud Endpointswith

Dartlang

Page 15: Dart flightschool cloudendpoint with dart

Google CloudEndpoints?

Page 16: Dart flightschool cloudendpoint with dart

https://developers.google.com/appengine/docs/java/endpoints/

What?Google CloudEndpoints?

Page 17: Dart flightschool cloudendpoint with dart

https://developers.google.com/appengine/docs/java/endpoints/

What?Google CloudEndpoints?

AppEngine 上にバックエンド API を簡単に作成する仕組

Page 18: Dart flightschool cloudendpoint with dart

https://developers.google.com/appengine/docs/java/endpoints/

What?Google CloudEndpoints?作成したAPI に対するクライアントライブラリを自動生成

Page 19: Dart flightschool cloudendpoint with dart

使える言語Google CloudEndpoints?

サーバサイド

PythonPythonでCloud Endpointsの事例をあまりみないのでどっか LTとかするとウケそう

Page 20: Dart flightschool cloudendpoint with dart

使える言語Google CloudEndpoints?

サーバサイド

Java事例もよく見るので始めるのは楽かもJAX-RSに似てるでも結構違う

http://www.flickr.com/photos/andypiper/

Page 21: Dart flightschool cloudendpoint with dart

使える言語Google CloudEndpoints?

サーバサイド

GoGoogleが直接サポートしているわけではなく、サードパーティツールを使う (後述 )個人的には好き

http://www.flickr.com/photos/andybons/

Page 22: Dart flightschool cloudendpoint with dart

クライアントGoogle CloudEndpoints?

自動生成ライブラリ

AndroidCloud Endpointsと触ったことが無い ( ー `д ー ´) キリッ

https://www.flickr.com/photos/etnyk/

Page 23: Dart flightschool cloudendpoint with dart

クライアントGoogle CloudEndpoints?

自動生成ライブラリ

iPhone持ってない ( ー `д ー ´) キリッ

https://www.flickr.com/photos/reticulating/

Page 24: Dart flightschool cloudendpoint with dart

クライアントGoogle CloudEndpoints?

自動生成ライブラリ

JavaScript自動生成できる、Google API client for JavaScript経由で利用時に作成されたものが使える感じ?

NoImage

Page 25: Dart flightschool cloudendpoint with dart

クライアントGoogle CloudEndpoints?

自動生成ライブラリ

Dartココに来てやっと ( ー `д ー ´) キリッただ Googleがサポートしているわけではなくサードパーティ製

Page 26: Dart flightschool cloudendpoint with dart

Google CloudEndpoints

TRY

Page 27: Dart flightschool cloudendpoint with dart

Google CloudEndpoints

TRY

Page 28: Dart flightschool cloudendpoint with dart

Google CloudEndpoints

TRY

Third party Third party

Page 29: Dart flightschool cloudendpoint with dart

サーバサイドGoogle CloudEndpoints

TRY

環境• Appengine Go SDK• Macユーザは brewからでも OK

$ brew install go-app-engine-64

Page 30: Dart flightschool cloudendpoint with dart

サーバサイドGoogle CloudEndpoints

TRY

ライブラリインストール• go-endpointsを使います

$ go get github.com/crhym3/go-endpoints/endpoints※インストール時にエラーが出ますが気にしないでください。

Page 31: Dart flightschool cloudendpoint with dart

サーバサイドGoogle CloudEndpoints

TRY

通信用構造体 (struct)を作成• go-endpointsが自動で

JSON←→Struct変換してくれます。

Page 32: Dart flightschool cloudendpoint with dart

サーバサイドGoogle CloudEndpoints

TRY

通信用構造体 (struct)を作成

Page 33: Dart flightschool cloudendpoint with dart

サーバサイドGoogle CloudEndpoints

TRY

サービス (実処理 )を作成• go-endpointsが変換した structを引数に渡してくれます。

Page 34: Dart flightschool cloudendpoint with dart

サーバサイドGoogle CloudEndpoints

TRY

サービス (実処理 )を作成

Page 35: Dart flightschool cloudendpoint with dart

サーバサイドGoogle CloudEndpoints

TRY

サービスを登録• サービスを go-endpontsに登録

Page 36: Dart flightschool cloudendpoint with dart

サーバサイドGoogle CloudEndpoints

TRY

サービスを登録

Page 37: Dart flightschool cloudendpoint with dart

サーバサイドGoogle CloudEndpoints

TRY

app.yamlで設定• go-endpontsが動くようにします。

application: my-app-idversion: v1threadsafe: true

runtime: goapi_version: go1

handlers:- url: /.* script: _go_app

# ここが絶対に必要- url: /_ah/spi/.* script: _go_app

Page 38: Dart flightschool cloudendpoint with dart

サーバサイドGoogle CloudEndpoints

TRY

起動• appengine go SDK経由

$ goapp serve

Page 39: Dart flightschool cloudendpoint with dart

サーバサイドGoogle CloudEndpoints

TRY

テスト• http://localhost:8080/_ah/api/explor

er

とかに行けば試せる

Page 40: Dart flightschool cloudendpoint with dart

サーバサイドGoogle CloudEndpoints

TRY

テスト

Page 41: Dart flightschool cloudendpoint with dart

サーバサイドGoogle CloudEndpoints

TRY

リリース• goapp deployでリリース

$ goapp deploy

Page 42: Dart flightschool cloudendpoint with dart

クライアントGoogle CloudEndpoints

TRY

ライブラリの Generatorをインスコ• Generatorがあるのでそれを

Githubから持ってきます。$ git clone

https://github.com/dart-gde/discovery_api_dart_client_generator

$ cd discovery_api_dart_client_generator

$ pub install

Page 43: Dart flightschool cloudendpoint with dart

クライアントGoogle CloudEndpoints

TRY

ライブラリを作成• generate.dartを呼び出し• dart_{APIの名前 }のディレクトリが出来る$

URL=‘https://hogehoge.appstop.com/_ah/api/discovery/v1/apis/greeting/v1/rest‘

$ curl -s -o greetings.rpc.discovery $URL

$ bin/generate.dart –I greetings.rpc.discovery –o ../ --no-prefix

Page 44: Dart flightschool cloudendpoint with dart

使い方Google CloudEndpoints

TRY

設定• pubspec.yamlでローカルライブラリを呼び出し

name: GreetingAppdescription: A sample web applicationdependencies: browser: any greeting_v1_api : path : /path/to/dart_greeting_v1_api_client

Page 45: Dart flightschool cloudendpoint with dart

使い方Google CloudEndpoints

TRY

Import• {API名 }_browser.dart

{API名 }_client.dartを import

import 'package:greeting_v1_api/greeting_v1_api_browser.dart' as greetingLib;import 'package:greeting_v1_api/greeting_v1_api_client.dart' as greetingClient; 

Page 46: Dart flightschool cloudendpoint with dart

使い方Google CloudEndpoints

TRY

呼び出し

greetingLib.Greeting greeting = new greetingLib.Greeting(); greeting.greets.list().then( (greetingClient.GreetingsList value)=> print(value) ); 

• {API名 }_client側にある {API名 }のインスタンスを作成し、呼び出し

Page 47: Dart flightschool cloudendpoint with dart

Google CloudEndpoints

TRY

Demo

Page 48: Dart flightschool cloudendpoint with dart

使い所 ?Google CloudEndpoints

TRY

使いドコロ• コンソールアプリケーション• Chrome Extension/App• Chrome Appなら cordovaとか経由で Android/iPhoneでも使えるかも ?

• 割りと大規模なプロジェクト ?

Page 49: Dart flightschool cloudendpoint with dart

End

Page 50: Dart flightschool cloudendpoint with dart

Appendix

元 GWTTER から見たDart

Page 51: Dart flightschool cloudendpoint with dart

お願いアンケートにご協力

を!http://goo.gl/98QcPN