You are on page 1of 44

BaaS

Logro

Al finalizar la sesión, el estudiante


construye experiencias móviles
nativas que interactúan con
servicios externos para
almacenamiento de datos.
Temario

• Middleware & Server Side


• API
• RESTful Services
• JSON
• BaaS & MBaaS
• Firebase
TEMA # 1

Middleware & Server Side


Introducción

En la actualidad las aplicaciones móviles nativas


requieren integración con servicios externos, con el fin
de brindar mayor funcionalidad, centralizando
información, delegando complejidad.
Introducción

En la actualidad las aplicaciones móviles nativas


requieren integración con servicios externos, con el fin
de brindar mayor funcionalidad, centralizando
información, delegando complejidad.

¿Cómo?
Middleware

“Software that mediates between an application


program and a network. It manages the interaction
between disparate applications across the
heterogeneous computing platforms.”
- Webster
Middleware

“Software that mediates between an application


program and a network. It manages the interaction
between disparate applications across the
heterogeneous computing platforms.”
- Webster

¿Qué ejemplos de Middleware podemos nombrar?


Server-side

“Processing or content generation that is done on the


web server or other server, as opposed to on the client
computer where the web browser is running.”
- dictionary.com/browse/server-side
Server-side

“Processing or content generation that is done on the


web server or other server, as opposed to on the client
computer where the web browser is running.”
- dictionary.com/browse/server-side
¿Podemos adaptar la definición a un contexto de
Mobile Apps?
TEMA # 2

RESTful API
REST

REpresentational State Transfer


RESTful

Web Services basados en arquitectura REST.


Implementan interacción basada en métodos HTTP
Aplican URI (Uniform Resource Identifier)
Representación de información en formato JSON
RESTful API

Application Programming Interface


Descompone una transacción en pequeños módulos
Cada módulo gestiona una parte de la transacción.
Aplica métodos basados en HTTP (RFC 2616)
RESTful API
RESTful API
RESTful API

GET (Read only access)


PUT (New resource)
DELETE (Remove resource)
POST (Update/Create resource)
RESTful API
TEMA # 3

JSON
JSON

JavaScript Object Notation


JSON

Colección de pares nombre / valor


Lista ordenada de valores

{"customers":[
{"firstName":"John", "lastName":"Doe"},
{"firstName":"Anna", "lastName":"Smith"},
{"firstName":"Peter", "lastName":"Jones"}
]}
JSON Files

Extensión .JSON
MIME Type “application/json”
JSON & RoR

Ruby on Rails brinda soporte integrado para JSON


class UsersController < ApplicationController
def index
@users = User.all
respond_to do |format|
format.html # index.html.erb
format.xml { render xml: @users}
format.json { render json: @users}
end
end
end
GSON

Gradle

compile 'com.google.code.gson:gson:2.2.4'
GSON

Primitivas
// Serialization
Gson gson = new Gson();
gson.toJson(1); // ==> 1
gson.toJson("abcd"); // ==> "abcd"
gson.toJson(new Long(10)); // ==> 10
int[] values = { 1 };
gson.toJson(values); // ==> [1]

// Deserialization
int one = gson.fromJson("1", int.class);
Integer one = gson.fromJson("1", Integer.class);
Long one = gson.fromJson("1", Long.class);
Boolean false = gson.fromJson("false", Boolean.class);
String str = gson.fromJson("\"abc\"", String.class);
String[] anotherStr = gson.fromJson("[\"abc\"]", String[].class);
TEMA # 3

BaaS & MBaaS


BaaS

BaaS = Backend as a Service


Expone recursos vía API
BaaS

MBaaS = Mobile Backend as s Service


Brinda además Mobile SDK
BaaS Features
BaaS Features

Storage
Push notifications
Usage Analytics
Dashboard/UI
User Administration & Social Integration
Custom Code Integration
BaaS/MBaaS Providers

Algunos proveedores

AnyPresence back{4}app
ApiOmat Built.io
Appcelerator CloudKit
Arrow Google Cloud Platform
Appery.io & Firebase
Appmobi Kinvey
AWS Mobile Microsoft Azure Mobile
Hub Services
TEMA # 4

Firebase
Carácterísticas
Proyectos

Prerrequisitos

Android OS, Mínimo 2.3


Google Play services 10.0.1 o superior
Google Play services SDK
Android Studio 2.X
Proyectos

Agregar a proyecto

Alternativas:
• Firebase Assistant en Android Studio (Menú Tools > Firebase).
• Agregar manualmente en Firebase console
(https://console.firebase.google.com).
Proyectos

Bibliotecas
Gradle Dependency Line Service
com.google.firebase:firebase-core:10.0.1 Analytics

com.google.firebase:firebase-database:10.0.1 Realtime Database

com.google.firebase:firebase-storage:10.0.1 Storage

com.google.firebase:firebase-crash:10.0.1 Crash Reporting

com.google.firebase:firebase-auth:10.0.1 Authentication

com.google.firebase:firebase-messaging:10.0.1 Cloud Messaging and Notifications

com.google.firebase:firebase-config:10.0.1 Remote Config

com.google.firebase:firebase-invites:10.0.1 Invites and Dynamic Links

com.google.firebase:firebase-ads:10.0.1 AdMob

com.google.firebase:firebase-appindexing:10.0.1 App Indexing


Realtime Database

Agregar

Gradle

com.google.firebase:firebase-database:10.0.1

Configurar reglas

Autenticación
Acceso público
Realtime Database

Guardar
getInstance()
getReference()

// Write a message to the database


FirebaseDatabase database = FirebaseDatabase.getInstance();
DatabaseReference myRef = database.getReference("message");

myRef.setValue("Hello, World!");
Realtime Database

Leer
addValueEventListener()
Override de método onDataChange()
// Read from the database
myRef.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
// This method is called once with the initial value and again
// whenever data at this location is updated.
String value = dataSnapshot.getValue(String.class);
Log.d(TAG, "Value is: " + value);
}

@Override
public void onCancelled(DatabaseError error) {
// Failed to read value
Log.w(TAG, "Failed to read value.", error.toException());
}
});
Realtime Database

Estructurar datos
Evite anidar datos
Aplane las estructuras de datos
Cree estructuras de datos que escalen
Realtime Database

Estructurar datos
// An index to track Ada's memberships
{
"users": {
"alovelace": {
"name": "Ada Lovelace",
// Index Ada's groups in her profile
"groups": {
// the value here doesn't matter, just that the key exists
"techpioneers": true,
"womentechmakers": true
}
},
...
},
"groups": {
"techpioneers": {
"name": "Historical Tech Pioneers",
"members": {
"alovelace": true,
"ghopper": true,
"eclarke": true
}
},
...
}
}
Conclusiones

1 BaaS

2 Backend 4 RESTful 7 JSON 9 MBaaS

3 Server side 5 REST 8 JSON Files 10 Firebase

6 RESTful API
Bibliografía

• Cognizant – Why MBaaS Now


https://www.cognizant.com/whitepapers/why-mbaas-now-codex1194.pdf

• TechTarget - Mobile Backend as a Service


http://searchmobilecomputing.techtarget.com/definition/mobile-Backend-as-a-Service-mobile-BaaS

• Waracle – How to Choose the right Backend as a Service Platform


https://waracle.net/how-to-choose-the-right-backend-as-a-service-baas-platform/

• GSON
https://github.com/google/gson

• Firebase
https://firebase.google.com
Material producido por la Universidad Peruana de Ciencias Aplicadas
Autor: Ángel Augusto Velásquez Núñez
COPYRIGHT ©UPC 2016 - Todos los derechos reservados.