Backend em aplicaes Android - Google I/O 2015

  • Published on
    11-Aug-2015

  • View
    237

  • Download
    3

Transcript

  1. 1. Copyright 2015 Google IncCopyright 2015 Google Inc Intro to Mobile Backend Thales Lima
  2. 2. Copyright 2015 Google Inc Agenda Google App Engine Google Cloud Endpoints Datastore 1 2 3 4 Codelab
  3. 3. Copyright 2015 Google Inc Aplicativos do Google App Engine so fceis de criar, manter e escalar. Deixe o Google gerenciar os servidores para voc. Images by Connie Zhou
  4. 4. Copyright 2015 Google Inc App Engine Images by Connie Zhou Platform-as-a-service "Eu escrevo a app, voc gerencia meus servidores" Fcil para construir, manter e escalar Suporte para Python, Java, PHP e Go
  5. 5. Copyright 2015 Google Inc App Engine Images by Connie Zhou Escalabilidade automtica sem necessidade de configurao Foco no cdigo com deploy simples e servidor local para testes Algumas necessidades de adaptao no cdigo Timeouts de 60 segundos para requisies em instancias frontend
  6. 6. Copyright 2015 Google Inc Images by Connie Zhou Cloud Endpoints Facilita a criao de API de backend no App Engine Oferece autenticao OAuth Fcil para construir, manter e escalar
  7. 7. Copyright 2015 Google Inc Images by Connie Zhou Cloud Endpoints Possui recursos especiais no Android Studio Fcil de criar os backends e os clients para o backend via wizards (Android, IOS e JS) Necessidades de adaptao do cdigo Associado ao Google Cloud Platform
  8. 8. Copyright 2015 Google Inc User Images by Connie Zhou Cloud Datastore NoSql Store Autoscale and management Key: joe@ex.com email: joe@ex.com followees: [usr2@ex.com, usr3@ex.com] followers: Entities Kinds Keys Properties "Table" "Primary key" "Field" "Row"
  9. 9. Copyright 2015 Google Inc Google Cloud Platform 1 - Criar conta no Google Cloud Platform https://console.developers.google.com 2 - Criar projeto
  10. 10. Copyright 2015 Google Inc Android Studio - Cloud Endpoints 3 - Criar modulo de Java Endpoints
  11. 11. Copyright 2015 Google Inc Android Studio - Cloud Endpoints 4 - Alterar classe MyEndpoint e acrescentar mtodos para gerenciar as tarefas
  12. 12. 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 manipulao 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);
  13. 13. Copyright 2015 Google Inc Deploy Cloud Endpoint 10 - Publicar Api em App Engine
  14. 14. 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
  15. 15. 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();
  16. 16. Copyright 2015 Google Inc Aplicativo de tarefas Amazene as tarefas na nuvem Codelab Cloud Endpoints Datastore
  17. 17. Copyright 2015 Google Inc Contato Thales Lima thalesrml@gmail.com @thales_ https://github.com/thaleslima
  18. 18. Copyright 2015 Google Inc cloud.google.com Images by Connie Zhou