SlideShare a Scribd company logo
1 of 48
Download to read offline
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

More Related Content

What's hot

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

What's hot (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
 

Similar to 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
 

Similar to 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
 

More from Dimitar Danailov

More from 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
 

Recently uploaded

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
 
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
VictorSzoltysek
 

Recently uploaded (20)

Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
 
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
 
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 
Pharm-D Biostatistics and Research methodology
Pharm-D Biostatistics and Research methodologyPharm-D Biostatistics and Research methodology
Pharm-D Biostatistics and Research methodology
 
8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students
 
Sector 18, Noida Call girls :8448380779 Model Escorts | 100% verified
Sector 18, Noida Call girls :8448380779 Model Escorts | 100% verifiedSector 18, Noida Call girls :8448380779 Model Escorts | 100% verified
Sector 18, Noida Call girls :8448380779 Model Escorts | 100% verified
 
%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand
 
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdfAzure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
 
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
BUS PASS MANGEMENT SYSTEM USING PHP.pptx
BUS PASS MANGEMENT SYSTEM USING PHP.pptxBUS PASS MANGEMENT SYSTEM USING PHP.pptx
BUS PASS MANGEMENT SYSTEM USING PHP.pptx
 
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionIntroducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docx
 
Define the academic and professional writing..pdf
Define the academic and professional writing..pdfDefine the academic and professional writing..pdf
Define the academic and professional writing..pdf
 
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
 
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learn
 

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