18
Copyright 2015 Google Inc Copyright 2015 Google Inc Intro to Mobile Backend Thales Lima

Backend em aplicações Android - Google I/O 2015

Embed Size (px)

Citation preview

Copyright 2015 Google Inc

Copyright 2015 Google Inc

Intro to Mobile BackendThales Lima

Copyright 2015 Google Inc

Agenda

Google App Engine

Google Cloud Endpoints

Datastore

1

2

3

4 Codelab

Copyright 2015 Google Inc

Aplicativos do Google App Engine são fáceis de criar, manter e escalar. Deixe o Google gerenciar os servidores para você.

Images by Connie Zhou

Copyright 2015 Google Inc

App Engine

Images by Connie Zhou

• Platform-as-a-service

• "Eu escrevo a app, você gerencia meus servidores"

• Fácil para construir, manter e escalar

• Suporte para Python, Java, PHP e Go

Copyright 2015 Google Inc

App Engine

Images by Connie Zhou

• Escalabilidade automática sem necessidade de configuração

• Foco no código com deploy simples e servidor local para testes

• Algumas necessidades de adaptação no código

• Timeouts de 60 segundos para requisições em instancias frontend

Copyright 2015 Google Inc

Images by Connie Zhou

Cloud Endpoints

• Facilita a criação de API de backend no App Engine

• Oferece autenticação OAuth

• Fácil para construir, manter e escalar

Copyright 2015 Google Inc

Images by Connie Zhou

Cloud Endpoints

• Possui recursos especiais no Android Studio

• Fácil de criar os backends e os clients para o backend via wizards (Android, IOS e JS)

• Necessidades de adaptação do código

• Associado ao Google Cloud Platform

Copyright 2015 Google Inc

User

Images by Connie Zhou

Cloud Datastore

• NoSql Store

• Autoscale and management

Key: [email protected]: [email protected]: [[email protected], [email protected]]followers:

Entities

Kinds

Keys

Properties

"Table"

"Primary key"

"Field"

"Row"

Copyright 2015 Google Inc

Google Cloud Platform

1 - Criar conta no Google Cloud Platform https://console.developers.google.com

2 - Criar projeto

Copyright 2015 Google Inc

Android Studio - Cloud Endpoints

3 - Criar modulo de Java Endpoints

Copyright 2015 Google Inc

Android Studio - Cloud Endpoints

4 - Alterar classe MyEndpoint e acrescentar métodos para gerenciar as tarefas

Copyright 2015 Google Inc

Datastore

5 - Salvando dados no Datastore pelo Objectify

ofy().save().entity(entity).now()

6 - Listando dados no Datastore pelo Objectify

ofy().load().type(Tarefa.class).list()

7 - Deletando todos os dados no Datastore pelo Objectify

ofy().delete().entities(ofy().load().type(TaskBean.class).list()).now();

Objectify para manipulação de dados no Datastore

DatastoreService datastore =

DatastoreServiceFactory.

getDatastoreService();

Entity employee = new Entity("Employee");

employee.setProperty("name", "Antonio Salieri");

employee.setProperty("hireDate", new Date());

Key empKey = datastore.put(employee);

Copyright 2015 Google Inc

Deploy Cloud Endpoint

10 - Publicar Api em App Engine

Copyright 2015 Google Inc

Acessar api pelo App

12 - Adicionar referencia do modulo de backend ao gradle do aplicativo

compile project(path: ':backend-tarefas', configuration: 'android-endpoints')

11 - Rebuild projeto

Copyright 2015 Google Inc

Acessar api pelo App

14 - Executar metodos da API

MyBean bean = myApiService.sayHi(name).execute();

13 - Inicializar Cliente da API

private MyApi myApiService;

MyApi.Builder builder = new MyApi.Builder(AndroidHttp.newCompatibleTransport(), new AndroidJsonFactory(), null) .setRootUrl("https://project-id.appspot.com/_ah/api/") .setGoogleClientRequestInitializer( new GoogleClientRequestInitializer() { @Override public void initialize(AbstractGoogleClientRequest<?> abstractGoogleClientRequest) throws IOException { //abstractGoogleClientRequest.setDisableGZipContent(true); } } ); myApiService= builder.build();

Copyright 2015 Google Inc

● Aplicativo de tarefas

● Amazene as tarefas na nuvem

Codelab

Cloud Endpoints Datastore

Copyright 2015 Google Inc

Contato

Thales [email protected]@thales_

https://github.com/thaleslima

Copyright 2015 Google Inc

cloud.google.com

Images by Connie Zhou