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

%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
masabamasaba
 
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Medical / Health Care (+971588192166) Mifepristone and Misoprostol tablets 200mg
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
masabamasaba
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
Health
 

Dernier (20)

%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
 
WSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
WSO2Con2024 - Enabling Transactional System's Exponential Growth With SimplicityWSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
WSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
 
%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
 
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
 
WSO2CON 2024 Slides - Open Source to SaaS
WSO2CON 2024 Slides - Open Source to SaaSWSO2CON 2024 Slides - Open Source to SaaS
WSO2CON 2024 Slides - Open Source to SaaS
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
 
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
 
%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 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
 
%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
 
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open SourceWSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
 
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
 
%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
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
 
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...
 
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
 
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
 

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