SlideShare une entreprise Scribd logo
1  sur  48
Télécharger pour lire hors ligne
App Engine
Cloud Endpoints
@d_danailov
Google App Engine
Dimitar Danailov
Senior Developer at 158ltd.com
dimityr.danailov[at]gmail.com
Slideshare.net
Github
YouTube
Founder at VarnaIT
Topics Today
● Overview
● Architecture
● Software
● Java JDO support
● Commands
● Google API Explorer
● CustomizeREST Interface
Overview
Google Cloud Endpoints consists of tools, libraries and capabilities that
allow you to generate APIs and client libraries from an App Engine
application, referred to as an API backend, to simplify client access to
data from other applications. Endpoints makes it easier to create a web
backend for web clients and mobile clients such as Android or Apple's
iOS.
Basic Endpoints
Architecture
Software
Demo Project
Beer Class
public class Beer {
private Long id ;
private String beerName ;
private String kindOfBeer ;
private Long score ;
private Long numberOfDrinks ;
private Text image ;
private String country ;
private String description ;
private Double latitude ;
private Double longitude ;
public Long getId () {
return id ;
}
public void setId ( Long id ) {
this . id = id ;
}
// Getter and Setters
}
Java Data Objects (JDO) is a specification of Java object persistence.
One of its features is a transparency of the persistence services to the
domain model. JDO persistent objects are ordinary Java programming
language classes (POJOs); there is no requirement for them to
implement certain interfaces or extend from special classes.
Java JDO support
import javax.jdo.annotations.IdGeneratorStrategy ;
import javax.jdo.annotations.IdentityType ;
import javax.jdo.annotations.PersistenceCapable ;
import javax.jdo.annotations.Persistent ;
import javax.jdo.annotations.PrimaryKey ;
@PersistenceCapable ( identityType = IdentityType. APPLICATION )
public class Beer {
@PrimaryKey
@Persistent ( valueStrategy = IdGeneratorStrategy. IDENTITY )
private Long id ;
Java JDO support (2)
@Api(name = "birra")
In line 1 above we use the @Api attribute.
This attribute tells App Engine to expose this class as a RESTRPC
endpoints.
Be aware that all the public methods on this class will be accessible via
REST endpoint.
I have also changed the name to birra to match with the rest of the
application.
@Api
1. List Beers
a. curl http://localhost:8888/_ah/api/birra/v1/beer
2. Create a Bear
a. curl -H 'Content-Type: appilcation/json' -d
'{"beerName": "bud"}' http://localhost:
8888/_ah/api/birra/v1/beer
3. Get a Beer
a. curl http://localhost:8888/_ah/api/birra/v1/beer/1
Commands
@ApiMethod(name = "insertBeer")
public Beer insertBeer (Beer beer) {
PersistenceManager mgr = getPersistenceManager ();
try {
if (containsCar(beer)) {
throw new EntityExistsException ("Object already exists ");
}
mgr.makePersistent (beer);
} finally {
mgr.close();
}
return beer;
}
Fix - Before
@ApiMethod(name = "insertBeer")
public Beer insertBeer (Beer beer) {
PersistenceManager mgr = getPersistenceManager ();
try {
if (beer.getId() != null) {
if (containsCar(beer)) {
throw new EntityExistsException ("Object already
exists");
}
}
mgr.makePersistent (beer);
} finally {
mgr.close();
}
return beer;
}
Fix - After
https://<appid>.appspot.
com/_ah/api/discovery/v1/apis
Google API
Explorer
https://<appid>.
appspot.
com/_ah/api/expl
orer
Comment Class
import com.google.appengine.api.users.User;
import javax.jdo.annotations.IdGeneratorStrategy ;
import javax.jdo.annotations.IdentityType ;
import javax.jdo.annotations.PersistenceCapable ;
import javax.jdo.annotations.Persistent ;
import javax.jdo.annotations.PrimaryKey ;
@PersistenceCapable (identityType = IdentityType.APPLICATION)
public class Comment {
@PrimaryKey
@Persistent ( valueStrategy = IdGeneratorStrategy . IDENTITY
)
private Long commentId;
private User user;
private String date;
private Long beerId;
private String comment;
// Getter and Setters
}
Customize
REST Interface
@ApiMethod(name = "beers.comments.list", path =
"beers/{beerId}/comments")
public CollectionResponse < Comment > listComment(
@Named("beerId") Long beerId,
@Nullable@ Named("cursor") String cursorString,
@Nullable@ Named("limit") Integer limit) {
PersistenceManager mgr = null;
Cursor cursor = null;
List < Comment > execute = null;
try {
mgr = getPersistenceManager();
Query query = mgr.newQuery(Comment.class,
"beerId == " + beerId);
// ...
@ApiMethod(name = "beers.get.comment", path =
"beers/{beerId}/comments/{id}")
public Comment getComment(@Named("beerId") Long
beerId, @Named("id") Long id) {
@ApiMethod(name = "beers.comments.insert", path =
"beers/{beerId}/comments")
public Comment insertComment(@Named ( "beerId" )
Long beerId, Comment comment) {
Customize REST Interface (2)
private static final Index INDEX = getIndex();
private static Index getIndex() {
IndexSpec indexSpec = IndexSpec.newBuilder()
.setName("beerindex").build();
Index indexServiceFactory =
SearchServiceFactory.getSearchService().getIndex
(indexSpec);
return indexServiceFactory;
}
Search
Add Beers to that Index
private static void addBeerToSearchIndex(Beer beer) {
Document.Builder docBuilder = Document.newBuilder();
/*** Id ***/
Long beerId = beer.getId();
docBuilder .addField(Field.newBuilder().setName("id").setText
(Long.toString(beerId)));
/*** Name ***/
String beerName = beer.getBeerName();
String docBuilderName = "";
if (beerName != null) {
docBuilderName = beerName;
}
docBuilder .addField(Field.newBuilder().setName("name").setText
(docBuilderName ));
/*** Name ***/
/*** … ***/
private static void addBeerToSearchIndex(Beer beer) {
/*** … ***/
/*** Latitude ***/
Double beerLatitude = beer.getLatitude();
Double docBulderLatitude = (double) 0;
if (beerLatitude != null) {
docBulderLatitude = beerLatitude;
}
docBuilder .addField(Field.newBuilder().setName("latitude").setNumber
(docBulderLatitude ));
/*** Latitude ***/
/*** Score ***/
Long beerScore = beer.getScore();
Long docBuilderScore = (long) 0;
if (beerScore != null) {
docBuilderScore = beerScore;
}
docBuilder.addField(Field.newBuilder().setName("score").
setNumber(docBuilderScore));
/*** Score ***/
docBuilder.addField(Field.newBuilder().setName("published").
setDate(new Date()));
docBuilder.setId(Long.toString(beerId));
Document document = docBuilder.build();
INDEX.put(document);
}
Search
@ApiMethod(httpMethod = "GET", name = "beer.search")
public List < Beer > searchBeer(@Named("term") String queryString) {
List < Beer > beerList = new ArrayList < Beer > ();
Results < ScoredDocument > results = INDEX.search(queryString);
for (ScoredDocument scoredDoc : results) {
try {
Field f = scoredDoc.getOnlyField("id");
if (f == null || f.getText() == null) continue;
long beerId = Long.parseLong(f.getText());
if (beerId != -1) {
Beer b = getBeer(beerId);
beerList .add(b);
}
} catch (Exception e) {
e.printStackTrace ();
}
}
return beerList;
Tutorials
● Overview of Google Cloud Endpoints
● Deploy the Backend
● HTML5 and App Engine: The Epic Tag Team Take on Modern
Web Apps at Scale
● GDC 2013 - Connect Mobile Apps to the Cloud Without Breaking
a Sweat
● Google Cloud Endpoints - Varna Lab 25.09.2013
Source
● http://www.networkworld.com
● http://upload.wikimedia.org
● http://cdn.techinasia.com
● http://en.wikipedia.org
● https://developers.google.com/
● http://www.bg-mamma.com/
● http://stackoverflow.com/
● https://www.youtube.com
Questions ?
Dimitar Danailov
Senior Developer at 158ltd.com
dimityr.danailov[at]gmail.com
Slideshare.net
Github
YouTube
Founder at VarnaIT

Contenu connexe

Tendances

Quick Start to iOS Development
Quick Start to iOS DevelopmentQuick Start to iOS Development
Quick Start to iOS Development
Jussi Pohjolainen
 

Tendances (20)

Angular modules in depth
Angular modules in depthAngular modules in depth
Angular modules in depth
 
TDC2016SP - Trilha Android
TDC2016SP - Trilha AndroidTDC2016SP - Trilha Android
TDC2016SP - Trilha Android
 
Introduction To CodeIgniter
Introduction To CodeIgniterIntroduction To CodeIgniter
Introduction To CodeIgniter
 
Android dev tips
Android dev tipsAndroid dev tips
Android dev tips
 
Angular 8
Angular 8 Angular 8
Angular 8
 
Angular Workshop_Sarajevo2
Angular Workshop_Sarajevo2Angular Workshop_Sarajevo2
Angular Workshop_Sarajevo2
 
Code igniter - A brief introduction
Code igniter - A brief introductionCode igniter - A brief introduction
Code igniter - A brief introduction
 
Angular IO
Angular IOAngular IO
Angular IO
 
Dependency Injection, Zend Framework and Symfony Container
Dependency Injection, Zend Framework and Symfony ContainerDependency Injection, Zend Framework and Symfony Container
Dependency Injection, Zend Framework and Symfony Container
 
Hilt Annotations
Hilt AnnotationsHilt Annotations
Hilt Annotations
 
Apigee Console & eZ Publish REST
Apigee Console & eZ Publish RESTApigee Console & eZ Publish REST
Apigee Console & eZ Publish REST
 
AspMVC4 start101
AspMVC4 start101AspMVC4 start101
AspMVC4 start101
 
Azure mobile apps
Azure mobile appsAzure mobile apps
Azure mobile apps
 
Sharper Better Faster Dagger ‡ - Droidcon SF
Sharper Better Faster Dagger ‡ - Droidcon SFSharper Better Faster Dagger ‡ - Droidcon SF
Sharper Better Faster Dagger ‡ - Droidcon SF
 
Extend sdk
Extend sdkExtend sdk
Extend sdk
 
Creating web api and consuming- part 1
Creating web api and consuming- part 1Creating web api and consuming- part 1
Creating web api and consuming- part 1
 
Having fun with code igniter
Having fun with code igniterHaving fun with code igniter
Having fun with code igniter
 
Building a TV show with Angular, Bootstrap, and Web Services
Building a TV show with Angular, Bootstrap, and Web ServicesBuilding a TV show with Angular, Bootstrap, and Web Services
Building a TV show with Angular, Bootstrap, and Web Services
 
Quick Start to iOS Development
Quick Start to iOS DevelopmentQuick Start to iOS Development
Quick Start to iOS Development
 
Technozaure - Angular2
Technozaure - Angular2Technozaure - Angular2
Technozaure - Angular2
 

Similaire à Google Cloud Endpoints - Soft Uni 19.06.2014

Making Things Work Together
Making Things Work TogetherMaking Things Work Together
Making Things Work Together
Subbu Allamaraju
 
Parse cloud code
Parse cloud codeParse cloud code
Parse cloud code
維佋 唐
 
Coocoo for Cocoapods
Coocoo for CocoapodsCoocoo for Cocoapods
Coocoo for Cocoapods
Allan Davis
 

Similaire à Google Cloud Endpoints - Soft Uni 19.06.2014 (20)

apiDoc Introduction
apiDoc IntroductionapiDoc Introduction
apiDoc Introduction
 
Making Things Work Together
Making Things Work TogetherMaking Things Work Together
Making Things Work Together
 
Building an Android app with Jetpack Compose and Firebase
Building an Android app with Jetpack Compose and FirebaseBuilding an Android app with Jetpack Compose and Firebase
Building an Android app with Jetpack Compose and Firebase
 
API Workshop: Deep dive into REST APIs
API Workshop: Deep dive into REST APIsAPI Workshop: Deep dive into REST APIs
API Workshop: Deep dive into REST APIs
 
SP Rest API Documentation
SP Rest API DocumentationSP Rest API Documentation
SP Rest API Documentation
 
Introduction to Spring Boot.pdf
Introduction to Spring Boot.pdfIntroduction to Spring Boot.pdf
Introduction to Spring Boot.pdf
 
MongoDB World 2018: Tutorial - Got Dibs? Building a Real-Time Bidding App wit...
MongoDB World 2018: Tutorial - Got Dibs? Building a Real-Time Bidding App wit...MongoDB World 2018: Tutorial - Got Dibs? Building a Real-Time Bidding App wit...
MongoDB World 2018: Tutorial - Got Dibs? Building a Real-Time Bidding App wit...
 
Cgi
CgiCgi
Cgi
 
How to build RESTful API in 15 Minutes.pptx
How to build RESTful API in 15 Minutes.pptxHow to build RESTful API in 15 Minutes.pptx
How to build RESTful API in 15 Minutes.pptx
 
Serverless Framework Workshop - Tyler Hendrickson, Chicago/burbs
 Serverless Framework Workshop - Tyler Hendrickson, Chicago/burbs Serverless Framework Workshop - Tyler Hendrickson, Chicago/burbs
Serverless Framework Workshop - Tyler Hendrickson, Chicago/burbs
 
Gears User Guide
Gears User GuideGears User Guide
Gears User Guide
 
Parse cloud code
Parse cloud codeParse cloud code
Parse cloud code
 
Introduction To Code Igniter
Introduction To Code IgniterIntroduction To Code Igniter
Introduction To Code Igniter
 
Itb 2021 - Bulding Quick APIs by Gavin Pickin
Itb 2021 - Bulding Quick APIs by Gavin PickinItb 2021 - Bulding Quick APIs by Gavin Pickin
Itb 2021 - Bulding Quick APIs by Gavin Pickin
 
HTML5 tutorial: canvas, offfline & sockets
HTML5 tutorial: canvas, offfline & socketsHTML5 tutorial: canvas, offfline & sockets
HTML5 tutorial: canvas, offfline & sockets
 
Codegnitorppt
CodegnitorpptCodegnitorppt
Codegnitorppt
 
ApacheCon Testing Camel K with Cloud Native BDD
ApacheCon Testing Camel K with Cloud Native BDDApacheCon Testing Camel K with Cloud Native BDD
ApacheCon Testing Camel K with Cloud Native BDD
 
Coocoo for Cocoapods
Coocoo for CocoapodsCoocoo for Cocoapods
Coocoo for Cocoapods
 
Red5 - PHUG Workshops
Red5 - PHUG WorkshopsRed5 - PHUG Workshops
Red5 - PHUG Workshops
 
Integrate any Angular Project into WebSphere Portal
Integrate any Angular Project into WebSphere PortalIntegrate any Angular Project into WebSphere Portal
Integrate any Angular Project into WebSphere Portal
 

Plus de Dimitar Danailov

Plus de Dimitar Danailov (20)

Evolution - ReConnect() 2019
Evolution - ReConnect() 2019Evolution - ReConnect() 2019
Evolution - ReConnect() 2019
 
Data Visualization and D3Js
Data Visualization and D3JsData Visualization and D3Js
Data Visualization and D3Js
 
#Productivity - {S:01 Ep:03}
#Productivity - {S:01 Ep:03} #Productivity - {S:01 Ep:03}
#Productivity - {S:01 Ep:03}
 
#Productivity - {S:01 Ep:02}
#Productivity - {S:01 Ep:02}#Productivity - {S:01 Ep:02}
#Productivity - {S:01 Ep:02}
 
#Productivity s01 ep02
#Productivity s01 ep02#Productivity s01 ep02
#Productivity s01 ep02
 
#Productivity s01 ep01
#Productivity s01 ep01#Productivity s01 ep01
#Productivity s01 ep01
 
Cloud Conf Varna - Cloud Application with AWS Lambda functions
Cloud Conf Varna - Cloud Application with AWS Lambda functionsCloud Conf Varna - Cloud Application with AWS Lambda functions
Cloud Conf Varna - Cloud Application with AWS Lambda functions
 
DEV.BG - Angular 1 and Jasmine (Unit Testing and TDD)
DEV.BG - Angular 1 and Jasmine (Unit Testing and TDD)DEV.BG - Angular 1 and Jasmine (Unit Testing and TDD)
DEV.BG - Angular 1 and Jasmine (Unit Testing and TDD)
 
Building modern Progressive Web Apps with Polymer
Building modern Progressive Web Apps with PolymerBuilding modern Progressive Web Apps with Polymer
Building modern Progressive Web Apps with Polymer
 
Typescript - MentorMate Academy
Typescript - MentorMate AcademyTypescript - MentorMate Academy
Typescript - MentorMate Academy
 
HackConf2016 - Ruby on Rails: Unexpected journey
HackConf2016 - Ruby on Rails: Unexpected journeyHackConf2016 - Ruby on Rails: Unexpected journey
HackConf2016 - Ruby on Rails: Unexpected journey
 
Microservices - Code Voyagers Sofia
Microservices - Code Voyagers SofiaMicroservices - Code Voyagers Sofia
Microservices - Code Voyagers Sofia
 
Mongo DB Terms - Mentormate Academy
Mongo DB Terms - Mentormate AcademyMongo DB Terms - Mentormate Academy
Mongo DB Terms - Mentormate Academy
 
Startup Europe Week - Cloud Conf Varna & GDG Varna
Startup Europe Week - Cloud Conf Varna & GDG VarnaStartup Europe Week - Cloud Conf Varna & GDG Varna
Startup Europe Week - Cloud Conf Varna & GDG Varna
 
GDG Varna - Hadoop
GDG Varna - HadoopGDG Varna - Hadoop
GDG Varna - Hadoop
 
MicroServices: Advantages ans Disadvantages
MicroServices: Advantages ans DisadvantagesMicroServices: Advantages ans Disadvantages
MicroServices: Advantages ans Disadvantages
 
GDG Varna - EcmaScript 6
GDG Varna - EcmaScript 6GDG Varna - EcmaScript 6
GDG Varna - EcmaScript 6
 
Softuni.bg - Microservices
Softuni.bg - MicroservicesSoftuni.bg - Microservices
Softuni.bg - Microservices
 
Cloud Conf Varna: Vagrant and Amazon
Cloud Conf Varna: Vagrant and AmazonCloud Conf Varna: Vagrant and Amazon
Cloud Conf Varna: Vagrant and Amazon
 
HackConf2015 - Ruby on Rails: Unexpected journey
HackConf2015 - Ruby on Rails: Unexpected journeyHackConf2015 - Ruby on Rails: Unexpected journey
HackConf2015 - Ruby on Rails: Unexpected journey
 

Dernier

introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdfintroduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
VishalKumarJha10
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is inside
shinachiaurasa2
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
masabamasaba
 

Dernier (20)

introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdfintroduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
%in Durban+277-882-255-28 abortion pills for sale in Durban
%in Durban+277-882-255-28 abortion pills for sale in Durban%in Durban+277-882-255-28 abortion pills for sale in Durban
%in Durban+277-882-255-28 abortion pills for sale in Durban
 
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
 
10 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 202410 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 2024
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
Generic or specific? Making sensible software design decisions
Generic or specific? Making sensible software design decisionsGeneric or specific? Making sensible software design decisions
Generic or specific? Making sensible software design decisions
 
SHRMPro HRMS Software Solutions Presentation
SHRMPro HRMS Software Solutions PresentationSHRMPro HRMS Software Solutions Presentation
SHRMPro HRMS Software Solutions Presentation
 
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...
 
Architecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastArchitecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the past
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
 
%in Lydenburg+277-882-255-28 abortion pills for sale in Lydenburg
%in Lydenburg+277-882-255-28 abortion pills for sale in Lydenburg%in Lydenburg+277-882-255-28 abortion pills for sale in Lydenburg
%in Lydenburg+277-882-255-28 abortion pills for sale in Lydenburg
 
%+27788225528 love spells in Vancouver Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Vancouver Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Vancouver Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Vancouver Psychic Readings, Attraction spells,Br...
 
The Top App Development Trends Shaping the Industry in 2024-25 .pdf
The Top App Development Trends Shaping the Industry in 2024-25 .pdfThe Top App Development Trends Shaping the Industry in 2024-25 .pdf
The Top App Development Trends Shaping the Industry in 2024-25 .pdf
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
 
The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is inside
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdfPayment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
 

Google Cloud Endpoints - Soft Uni 19.06.2014

  • 2. Google App Engine Dimitar Danailov Senior Developer at 158ltd.com dimityr.danailov[at]gmail.com Slideshare.net Github YouTube Founder at VarnaIT
  • 3.
  • 4.
  • 5. Topics Today ● Overview ● Architecture ● Software ● Java JDO support ● Commands ● Google API Explorer ● CustomizeREST Interface
  • 6. Overview Google Cloud Endpoints consists of tools, libraries and capabilities that allow you to generate APIs and client libraries from an App Engine application, referred to as an API backend, to simplify client access to data from other applications. Endpoints makes it easier to create a web backend for web clients and mobile clients such as Android or Apple's iOS.
  • 8.
  • 9.
  • 12.
  • 14. public class Beer { private Long id ; private String beerName ; private String kindOfBeer ; private Long score ; private Long numberOfDrinks ; private Text image ; private String country ; private String description ; private Double latitude ; private Double longitude ; public Long getId () { return id ; } public void setId ( Long id ) { this . id = id ; } // Getter and Setters }
  • 15. Java Data Objects (JDO) is a specification of Java object persistence. One of its features is a transparency of the persistence services to the domain model. JDO persistent objects are ordinary Java programming language classes (POJOs); there is no requirement for them to implement certain interfaces or extend from special classes. Java JDO support
  • 16. import javax.jdo.annotations.IdGeneratorStrategy ; import javax.jdo.annotations.IdentityType ; import javax.jdo.annotations.PersistenceCapable ; import javax.jdo.annotations.Persistent ; import javax.jdo.annotations.PrimaryKey ; @PersistenceCapable ( identityType = IdentityType. APPLICATION ) public class Beer { @PrimaryKey @Persistent ( valueStrategy = IdGeneratorStrategy. IDENTITY ) private Long id ; Java JDO support (2)
  • 17.
  • 18. @Api(name = "birra") In line 1 above we use the @Api attribute. This attribute tells App Engine to expose this class as a RESTRPC endpoints. Be aware that all the public methods on this class will be accessible via REST endpoint. I have also changed the name to birra to match with the rest of the application. @Api
  • 19. 1. List Beers a. curl http://localhost:8888/_ah/api/birra/v1/beer 2. Create a Bear a. curl -H 'Content-Type: appilcation/json' -d '{"beerName": "bud"}' http://localhost: 8888/_ah/api/birra/v1/beer 3. Get a Beer a. curl http://localhost:8888/_ah/api/birra/v1/beer/1 Commands
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25. @ApiMethod(name = "insertBeer") public Beer insertBeer (Beer beer) { PersistenceManager mgr = getPersistenceManager (); try { if (containsCar(beer)) { throw new EntityExistsException ("Object already exists "); } mgr.makePersistent (beer); } finally { mgr.close(); } return beer; } Fix - Before
  • 26. @ApiMethod(name = "insertBeer") public Beer insertBeer (Beer beer) { PersistenceManager mgr = getPersistenceManager (); try { if (beer.getId() != null) { if (containsCar(beer)) { throw new EntityExistsException ("Object already exists"); } } mgr.makePersistent (beer); } finally { mgr.close(); } return beer; } Fix - After
  • 29.
  • 31. import com.google.appengine.api.users.User; import javax.jdo.annotations.IdGeneratorStrategy ; import javax.jdo.annotations.IdentityType ; import javax.jdo.annotations.PersistenceCapable ; import javax.jdo.annotations.Persistent ; import javax.jdo.annotations.PrimaryKey ; @PersistenceCapable (identityType = IdentityType.APPLICATION) public class Comment { @PrimaryKey @Persistent ( valueStrategy = IdGeneratorStrategy . IDENTITY ) private Long commentId; private User user; private String date; private Long beerId; private String comment; // Getter and Setters }
  • 33. @ApiMethod(name = "beers.comments.list", path = "beers/{beerId}/comments") public CollectionResponse < Comment > listComment( @Named("beerId") Long beerId, @Nullable@ Named("cursor") String cursorString, @Nullable@ Named("limit") Integer limit) { PersistenceManager mgr = null; Cursor cursor = null; List < Comment > execute = null; try { mgr = getPersistenceManager(); Query query = mgr.newQuery(Comment.class, "beerId == " + beerId); // ...
  • 34. @ApiMethod(name = "beers.get.comment", path = "beers/{beerId}/comments/{id}") public Comment getComment(@Named("beerId") Long beerId, @Named("id") Long id) { @ApiMethod(name = "beers.comments.insert", path = "beers/{beerId}/comments") public Comment insertComment(@Named ( "beerId" ) Long beerId, Comment comment) { Customize REST Interface (2)
  • 35.
  • 36.
  • 37. private static final Index INDEX = getIndex(); private static Index getIndex() { IndexSpec indexSpec = IndexSpec.newBuilder() .setName("beerindex").build(); Index indexServiceFactory = SearchServiceFactory.getSearchService().getIndex (indexSpec); return indexServiceFactory; } Search
  • 38. Add Beers to that Index
  • 39. private static void addBeerToSearchIndex(Beer beer) { Document.Builder docBuilder = Document.newBuilder(); /*** Id ***/ Long beerId = beer.getId(); docBuilder .addField(Field.newBuilder().setName("id").setText (Long.toString(beerId))); /*** Name ***/ String beerName = beer.getBeerName(); String docBuilderName = ""; if (beerName != null) { docBuilderName = beerName; } docBuilder .addField(Field.newBuilder().setName("name").setText (docBuilderName )); /*** Name ***/ /*** … ***/
  • 40. private static void addBeerToSearchIndex(Beer beer) { /*** … ***/ /*** Latitude ***/ Double beerLatitude = beer.getLatitude(); Double docBulderLatitude = (double) 0; if (beerLatitude != null) { docBulderLatitude = beerLatitude; } docBuilder .addField(Field.newBuilder().setName("latitude").setNumber (docBulderLatitude )); /*** Latitude ***/
  • 41. /*** Score ***/ Long beerScore = beer.getScore(); Long docBuilderScore = (long) 0; if (beerScore != null) { docBuilderScore = beerScore; } docBuilder.addField(Field.newBuilder().setName("score"). setNumber(docBuilderScore)); /*** Score ***/
  • 44. @ApiMethod(httpMethod = "GET", name = "beer.search") public List < Beer > searchBeer(@Named("term") String queryString) { List < Beer > beerList = new ArrayList < Beer > (); Results < ScoredDocument > results = INDEX.search(queryString); for (ScoredDocument scoredDoc : results) { try { Field f = scoredDoc.getOnlyField("id"); if (f == null || f.getText() == null) continue; long beerId = Long.parseLong(f.getText()); if (beerId != -1) { Beer b = getBeer(beerId); beerList .add(b); } } catch (Exception e) { e.printStackTrace (); } } return beerList;
  • 45. Tutorials ● Overview of Google Cloud Endpoints ● Deploy the Backend ● HTML5 and App Engine: The Epic Tag Team Take on Modern Web Apps at Scale ● GDC 2013 - Connect Mobile Apps to the Cloud Without Breaking a Sweat ● Google Cloud Endpoints - Varna Lab 25.09.2013
  • 46. Source ● http://www.networkworld.com ● http://upload.wikimedia.org ● http://cdn.techinasia.com ● http://en.wikipedia.org ● https://developers.google.com/ ● http://www.bg-mamma.com/ ● http://stackoverflow.com/ ● https://www.youtube.com
  • 47.
  • 48. Questions ? Dimitar Danailov Senior Developer at 158ltd.com dimityr.danailov[at]gmail.com Slideshare.net Github YouTube Founder at VarnaIT