SlideShare ist ein Scribd-Unternehmen logo
1 von 39
Consuming RESTFul APIs using
Swagger v2.0
Pece Nikolovski
My Story
Can you please provide API Specification for
your existing Web Service?
THE Web Service specification
● Some .txt or .doc or email containing this...
https://my.company.api/v1/login
https://my.company.api/v1/user
https://my.company.api/v1/cards
https://my.company.api/v1/phones
https://my.company.api/v1/addresses
https://my.company.api/v1/addresses/1
THE Web Service specification v2
Push request for login using username, password and deviceId(UUID)
https://my.company.api/v1/login
Get user details
https://my.company.api/v1/user
Get list of cards
https://my.company.api/v1/cards
Get list of phones
https://my.company.api/v1/phones
•••
My approach
● Deciphering phase
o Postman
● Document Web Service
o Use template doc
● Verify specification docs with client
● Let the coding begin
The “Web Service Document”
Common issues
● Developers “LOVE” documentation
o new api calls
o modification of existing
o maintenance of Web Service Docs
● Consistency between platforms
o iOS, Android and IS
● Etc.
What is Swagger?
Swagger
What is the meaning of Swagger?
What is Swagger?
● Simple representation of your RESTful
API
● Group of projects
o several main
o over 50 community
● http://swagger.io
Swagger Spec & Core
● Swagger syntax - Json or Yaml
o I prefer Yaml
● Models using JSON Schema draft v4
● https://github.com/swagger-api/swagger-spec
● https://github.com/swagger-api/swagger-core
How to create the Spec?
● Two approaches
o Automatic
o Manual
Our approach
Outware’s approach
● Why v2.0?
o Why not v1.2 or v1.0
● Lots of reasons…
o Java vs Scala
● Works in both cases
o building API and client
o only client
Manually build the Specs
● How to check specs validity?
o JSON, YAML, blah blah blah...
Swagger Editor
● Available on v2
● Validation of Swagger syntax
● Visually attractive
Online Validator
● Swagger Validator Badge
<img src="http://online.swagger.io/validator?url={YOUR_URL}">
Swagger UI
● Web Service documentation
o Interactive
● Directly test API calls and observe the results
Put validation in action
● JSON Schema Validator
o https://github.com/ruby-json-schema/json-schema
● Validate models based on spec file
What about mobile dev?
Swagger Codegen
● Generate client code based on spec
● Java / Maven project
● Output is auto generated ( & “documented code”)
● Multiple languages support
o Language client class
o Mustache template files
Android - How it works?
● Default setup - Out-Of-The-Box
o package, name, artefact id, version
● Run this command:
java -jar swagger-codegen-distribution-2.1.0.jar 
-i http://petstore.swagger.io/v2/swagger.json 
-l android 
-o samples/client/petstore/android
● Use generated code as maven dependency in Android project
Custom Android example
● Extend AndroidClientCodegen.java
o make necessary changes (package, name, version, etc…)
Custom Android example
● Re-package using: mvn package
● Generate client code:
java -jar swagger-codegen-distribution-2.1.0.jar

-i http://petstore.swagger.io/v2/swagger.json 
-l au.com.outware.MyAndroidCodegen 
-o samples/client/petstore/android
What is the quality of generated code?
● Code as good as your template
o Treat as “Black Box”
● Using HTTPRequest
● Errors returned as string instead models
● Minor bugs
o array http params
o form params
What we wanted?
● Retrofit
● OKHttp
● Gradle
● Proper Error Handling
● Javadoc and Sources available in Android project
● Outware’s fork
https://github.com/outware-mobile/swagger-codegen
How to use?
● Generate Retrofit client
java -jar swagger-codegen-distribution-2.1.0.jar 
-i http://petstore.swagger.io/v2/swagger.json 
-l android-retrofit 
-o samples/client/petstore/java
How to use?
● Local maven repo: Nexus or Artefactory (to publish .jar artefacts)
● Compile the generated code
o gradle build
o Jar files in (build/libs/*)
 APIs
 sources
 javadoc
● Publish artefacts
o gradle uploadRelease
How to use?
● Set as project dependency in build.gradle
repositories {
maven {
url 'http://your_maven_repo'
}
}
...
dependencies {
compile 'com.wordnik:io.swagger.client:1.0.0'
compile 'com.squareup.retrofit:retrofit:1.8.0'
compile 'com.squareup.okhttp:okhttp-urlconnection:2.1.0'
compile 'com.squareup.okhttp:okhttp:2.1.0'
}
iOS - How it works?
● Same as Android
● Default setup - Out-Of-The-Box
o generated files prefix
● Run this command:
java -jar swagger-codegen-distribution-2.1.0.jar 
-i http://petstore.swagger.io/v2/swagger.json 
-l objc 
-o samples/client/petstore/objc
● Copy generated code and include into project
Custom iOS example
● Extend ObjcClientCodegen.java
o make changes (file prefix, etc…)
Custom iOS example
● Re-package using: mvn package
● Generate client code:
java -jar swagger-codegen-distribution-2.1.0.jar

-i http://petstore.swagger.io/v2/swagger.json 
-l au.com.outware.MyObjcCodegen 
-o samples/client/petstore/objc
What we wanted
● AFNetworking v2
● Project dependency as Podspec
o similar approach as with Android
target :MyProject do
...
pod 'petstore-api'
end
● Error Message Handling - instead of returning NSError
● AppleDoc for API calls and models
Final piece of the puzzle
● Consistency
o versioning
o new api spec
o updated api spec
o bugfixes in templates
● The Web Service Repo
o both iOS and Android in same repo
● Automated in CI
o one click release
Approach Summary
● Design API specs using ‘Swagger Editor’
● Validate server responses with ‘Ruby JSON Schema Validator’
● Publish Swagger specs using ‘Swagger UI’
● Generate client code
o One repo for both iOS and Android
o Android as Maven dependency
o iOS as Podspec dependency
● Update project
o Small or Big Refactoring
Summary of Issues
● v2 in “development”
o Release 2.1.1-M1 on 18 Feb
● Bugs in the template files
● Not yet implemented
o Json schema model inheritance not supported
o Error model handling
o More languages support in v1.2
o Other issues
● Recompiling not efficient
o Poorly documented codebase
What’s next?
● Contribute to main repo
o Command line options
● Auth Support in Swagger
o Basic, OAuth v2.0, etc.
● Other new features
● Generating API integration stubs
● And FINALLY...
Join the Crew
Thank You
Pece Nikolovski
Outware Mobile - www.outware.com.au
The OMPodcast - All about the Mobile Industry

Weitere ähnliche Inhalte

Was ist angesagt?

Introduction to Spring Framework
Introduction to Spring FrameworkIntroduction to Spring Framework
Introduction to Spring FrameworkHùng Nguyễn Huy
 
Spring boot introduction
Spring boot introductionSpring boot introduction
Spring boot introductionRasheed Waraich
 
Spring boot - an introduction
Spring boot - an introductionSpring boot - an introduction
Spring boot - an introductionJonathan Holloway
 
Java REST API Comparison: Micronaut, Quarkus, and Spring Boot - jconf.dev 2020
Java REST API Comparison: Micronaut, Quarkus, and Spring Boot - jconf.dev 2020Java REST API Comparison: Micronaut, Quarkus, and Spring Boot - jconf.dev 2020
Java REST API Comparison: Micronaut, Quarkus, and Spring Boot - jconf.dev 2020Matt Raible
 
REST API and CRUD
REST API and CRUDREST API and CRUD
REST API and CRUDPrem Sanil
 
Spring Framework - AOP
Spring Framework - AOPSpring Framework - AOP
Spring Framework - AOPDzmitry Naskou
 
Introduction to Swagger
Introduction to SwaggerIntroduction to Swagger
Introduction to SwaggerKnoldus Inc.
 
Building a REST Service in minutes with Spring Boot
Building a REST Service in minutes with Spring BootBuilding a REST Service in minutes with Spring Boot
Building a REST Service in minutes with Spring BootOmri Spector
 
REST APIs with Spring
REST APIs with SpringREST APIs with Spring
REST APIs with SpringJoshua Long
 
Spring Framework - Spring Security
Spring Framework - Spring SecuritySpring Framework - Spring Security
Spring Framework - Spring SecurityDzmitry Naskou
 
What is REST API? REST API Concepts and Examples | Edureka
What is REST API? REST API Concepts and Examples | EdurekaWhat is REST API? REST API Concepts and Examples | Edureka
What is REST API? REST API Concepts and Examples | EdurekaEdureka!
 
Spring Security
Spring SecuritySpring Security
Spring SecuritySumit Gole
 
스프링처럼 JDBC 리팩터링하기
스프링처럼 JDBC 리팩터링하기 스프링처럼 JDBC 리팩터링하기
스프링처럼 JDBC 리팩터링하기 Chanwook Park
 
Nestjs MasterClass Slides
Nestjs MasterClass SlidesNestjs MasterClass Slides
Nestjs MasterClass SlidesNir Kaufman
 

Was ist angesagt? (20)

Introduction to Spring Framework
Introduction to Spring FrameworkIntroduction to Spring Framework
Introduction to Spring Framework
 
Spring Security
Spring SecuritySpring Security
Spring Security
 
Spring boot introduction
Spring boot introductionSpring boot introduction
Spring boot introduction
 
Spring boot - an introduction
Spring boot - an introductionSpring boot - an introduction
Spring boot - an introduction
 
Java REST API Comparison: Micronaut, Quarkus, and Spring Boot - jconf.dev 2020
Java REST API Comparison: Micronaut, Quarkus, and Spring Boot - jconf.dev 2020Java REST API Comparison: Micronaut, Quarkus, and Spring Boot - jconf.dev 2020
Java REST API Comparison: Micronaut, Quarkus, and Spring Boot - jconf.dev 2020
 
REST API and CRUD
REST API and CRUDREST API and CRUD
REST API and CRUD
 
Spring Framework - AOP
Spring Framework - AOPSpring Framework - AOP
Spring Framework - AOP
 
Introduction to Swagger
Introduction to SwaggerIntroduction to Swagger
Introduction to Swagger
 
An Introduction To REST API
An Introduction To REST APIAn Introduction To REST API
An Introduction To REST API
 
Building a REST Service in minutes with Spring Boot
Building a REST Service in minutes with Spring BootBuilding a REST Service in minutes with Spring Boot
Building a REST Service in minutes with Spring Boot
 
REST APIs with Spring
REST APIs with SpringREST APIs with Spring
REST APIs with Spring
 
Spring Framework - Spring Security
Spring Framework - Spring SecuritySpring Framework - Spring Security
Spring Framework - Spring Security
 
What is REST API? REST API Concepts and Examples | Edureka
What is REST API? REST API Concepts and Examples | EdurekaWhat is REST API? REST API Concepts and Examples | Edureka
What is REST API? REST API Concepts and Examples | Edureka
 
Spring Security
Spring SecuritySpring Security
Spring Security
 
API for Beginners
API for BeginnersAPI for Beginners
API for Beginners
 
Presentation swagger
Presentation swaggerPresentation swagger
Presentation swagger
 
Spring Boot
Spring BootSpring Boot
Spring Boot
 
스프링처럼 JDBC 리팩터링하기
스프링처럼 JDBC 리팩터링하기 스프링처럼 JDBC 리팩터링하기
스프링처럼 JDBC 리팩터링하기
 
Spring boot
Spring bootSpring boot
Spring boot
 
Nestjs MasterClass Slides
Nestjs MasterClass SlidesNestjs MasterClass Slides
Nestjs MasterClass Slides
 

Andere mochten auch

Swagger - make your API accessible
Swagger - make your API accessibleSwagger - make your API accessible
Swagger - make your API accessibleVictor Trakhtenberg
 
Understanding how to use Swagger and its tools
Understanding how to use Swagger and its toolsUnderstanding how to use Swagger and its tools
Understanding how to use Swagger and its toolsSwagger API
 
Swagger for-your-api
Swagger for-your-apiSwagger for-your-api
Swagger for-your-apiTony Tam
 
A Tour of Swagger for APIs
A Tour of Swagger for APIsA Tour of Swagger for APIs
A Tour of Swagger for APIsAllen Dean
 
Swagger in the API Lifecycle
Swagger in the API LifecycleSwagger in the API Lifecycle
Swagger in the API LifecycleOle Lensmar
 
Iterative Development with Swagger on the JDK
Iterative Development with Swagger on the JDKIterative Development with Swagger on the JDK
Iterative Development with Swagger on the JDKSwagger API
 
API Design first with Swagger
API Design first with SwaggerAPI Design first with Swagger
API Design first with SwaggerTony Tam
 
The Swagger Format becomes the Open API Specification: Standardizing descript...
The Swagger Format becomes the Open API Specification: Standardizing descript...The Swagger Format becomes the Open API Specification: Standardizing descript...
The Swagger Format becomes the Open API Specification: Standardizing descript...3scale
 
Swaggerで始めるモデルファーストなAPI開発
Swaggerで始めるモデルファーストなAPI開発Swaggerで始めるモデルファーストなAPI開発
Swaggerで始めるモデルファーストなAPI開発Takuro Sasaki
 
Mùa đông, 'mùa' của tai biến
Mùa đông, 'mùa' của tai biếnMùa đông, 'mùa' của tai biến
Mùa đông, 'mùa' của tai biếnyasmine601
 
Exclusive: Doctor cheating warnings expand to dermatology
Exclusive: Doctor cheating warnings expand to dermatologyExclusive: Doctor cheating warnings expand to dermatology
Exclusive: Doctor cheating warnings expand to dermatologylackadaisicalca89
 
Thuốc Lic Tốt Không
Thuốc Lic Tốt KhôngThuốc Lic Tốt Không
Thuốc Lic Tốt Khôngteodoro236
 
Terry C. Updated Resume
Terry C. Updated ResumeTerry C. Updated Resume
Terry C. Updated ResumeTerry Childers
 
Portfolio Pictures
Portfolio PicturesPortfolio Pictures
Portfolio PicturesBailey Bond
 
TouchPapua Profile (Ind)
TouchPapua Profile (Ind)TouchPapua Profile (Ind)
TouchPapua Profile (Ind)JangkauPapua
 

Andere mochten auch (19)

Swagger - make your API accessible
Swagger - make your API accessibleSwagger - make your API accessible
Swagger - make your API accessible
 
Understanding how to use Swagger and its tools
Understanding how to use Swagger and its toolsUnderstanding how to use Swagger and its tools
Understanding how to use Swagger and its tools
 
Swagger for-your-api
Swagger for-your-apiSwagger for-your-api
Swagger for-your-api
 
A Tour of Swagger for APIs
A Tour of Swagger for APIsA Tour of Swagger for APIs
A Tour of Swagger for APIs
 
Swagger in the API Lifecycle
Swagger in the API LifecycleSwagger in the API Lifecycle
Swagger in the API Lifecycle
 
Iterative Development with Swagger on the JDK
Iterative Development with Swagger on the JDKIterative Development with Swagger on the JDK
Iterative Development with Swagger on the JDK
 
API Design first with Swagger
API Design first with SwaggerAPI Design first with Swagger
API Design first with Swagger
 
Swagger code motion talk
Swagger code motion talkSwagger code motion talk
Swagger code motion talk
 
Swagger 入門
Swagger 入門Swagger 入門
Swagger 入門
 
The Swagger Format becomes the Open API Specification: Standardizing descript...
The Swagger Format becomes the Open API Specification: Standardizing descript...The Swagger Format becomes the Open API Specification: Standardizing descript...
The Swagger Format becomes the Open API Specification: Standardizing descript...
 
Swaggerで始めるモデルファーストなAPI開発
Swaggerで始めるモデルファーストなAPI開発Swaggerで始めるモデルファーストなAPI開発
Swaggerで始めるモデルファーストなAPI開発
 
Mùa đông, 'mùa' của tai biến
Mùa đông, 'mùa' của tai biếnMùa đông, 'mùa' của tai biến
Mùa đông, 'mùa' của tai biến
 
Exclusive: Doctor cheating warnings expand to dermatology
Exclusive: Doctor cheating warnings expand to dermatologyExclusive: Doctor cheating warnings expand to dermatology
Exclusive: Doctor cheating warnings expand to dermatology
 
Thuốc Lic Tốt Không
Thuốc Lic Tốt KhôngThuốc Lic Tốt Không
Thuốc Lic Tốt Không
 
Asp.net
Asp.netAsp.net
Asp.net
 
Terry C. Updated Resume
Terry C. Updated ResumeTerry C. Updated Resume
Terry C. Updated Resume
 
Portfolio Pictures
Portfolio PicturesPortfolio Pictures
Portfolio Pictures
 
Chandrakant Shakya. (1)
Chandrakant Shakya. (1)Chandrakant Shakya. (1)
Chandrakant Shakya. (1)
 
TouchPapua Profile (Ind)
TouchPapua Profile (Ind)TouchPapua Profile (Ind)
TouchPapua Profile (Ind)
 

Ähnlich wie Consuming Restful APIs using Swagger v2.0

How to generate a rest application - DevFest Vienna 2016
How to generate a rest application - DevFest Vienna 2016How to generate a rest application - DevFest Vienna 2016
How to generate a rest application - DevFest Vienna 2016johannes_fiala
 
Using JHipster for generating Angular/Spring Boot apps
Using JHipster for generating Angular/Spring Boot appsUsing JHipster for generating Angular/Spring Boot apps
Using JHipster for generating Angular/Spring Boot appsYakov Fain
 
Jcon 2017 How to use Swagger to develop REST applications
Jcon 2017 How to use Swagger to develop REST applicationsJcon 2017 How to use Swagger to develop REST applications
Jcon 2017 How to use Swagger to develop REST applicationsjohannes_fiala
 
How to generate a REST CXF3 application from Swagger ApacheConEU 2016
How to generate a REST CXF3 application from Swagger ApacheConEU 2016How to generate a REST CXF3 application from Swagger ApacheConEU 2016
How to generate a REST CXF3 application from Swagger ApacheConEU 2016johannes_fiala
 
Introduction to Angular 2
Introduction to Angular 2Introduction to Angular 2
Introduction to Angular 2Naveen Pete
 
Building Mobile Friendly APIs in Rails
Building Mobile Friendly APIs in RailsBuilding Mobile Friendly APIs in Rails
Building Mobile Friendly APIs in RailsJim Jeffers
 
Docker Enterprise Workshop - Technical
Docker Enterprise Workshop - TechnicalDocker Enterprise Workshop - Technical
Docker Enterprise Workshop - TechnicalPatrick Chanezon
 
Introduction to google endpoints
Introduction to google endpointsIntroduction to google endpoints
Introduction to google endpointsShinto Anto
 
Google app-engine-with-python
Google app-engine-with-pythonGoogle app-engine-with-python
Google app-engine-with-pythonDeepak Garg
 
WebSDK - Switching between service providers
WebSDK - Switching between service providersWebSDK - Switching between service providers
WebSDK - Switching between service providersHotstar
 
REST API 20.2 - Appworks Gateway Integration.pptx
REST API 20.2 - Appworks Gateway Integration.pptxREST API 20.2 - Appworks Gateway Integration.pptx
REST API 20.2 - Appworks Gateway Integration.pptxJason452803
 
Angular4 getting started
Angular4 getting startedAngular4 getting started
Angular4 getting startedTejinderMakkar
 
Remote Config REST API and Versioning
Remote Config REST API and VersioningRemote Config REST API and Versioning
Remote Config REST API and VersioningJumpei Matsuda
 
Gatling Performance Workshop
Gatling Performance WorkshopGatling Performance Workshop
Gatling Performance WorkshopSai Krishna
 
Parse cloud code
Parse cloud codeParse cloud code
Parse cloud code維佋 唐
 
NetDevOps Development Environments
NetDevOps Development EnvironmentsNetDevOps Development Environments
NetDevOps Development EnvironmentsJoel W. King
 
WSO2 Product Release Webinar - WSO2 App Factory 2.1
WSO2 Product Release Webinar - WSO2 App Factory 2.1WSO2 Product Release Webinar - WSO2 App Factory 2.1
WSO2 Product Release Webinar - WSO2 App Factory 2.1WSO2
 
JS Fest 2019/Autumn. Влад Федосов. Technology agnostic microservices at SPA f...
JS Fest 2019/Autumn. Влад Федосов. Technology agnostic microservices at SPA f...JS Fest 2019/Autumn. Влад Федосов. Technology agnostic microservices at SPA f...
JS Fest 2019/Autumn. Влад Федосов. Technology agnostic microservices at SPA f...JSFestUA
 
JSFest 2019: Technology agnostic microservices at SPA frontend
JSFest 2019: Technology agnostic microservices at SPA frontendJSFest 2019: Technology agnostic microservices at SPA frontend
JSFest 2019: Technology agnostic microservices at SPA frontendVlad Fedosov
 

Ähnlich wie Consuming Restful APIs using Swagger v2.0 (20)

How to generate a rest application - DevFest Vienna 2016
How to generate a rest application - DevFest Vienna 2016How to generate a rest application - DevFest Vienna 2016
How to generate a rest application - DevFest Vienna 2016
 
Using JHipster for generating Angular/Spring Boot apps
Using JHipster for generating Angular/Spring Boot appsUsing JHipster for generating Angular/Spring Boot apps
Using JHipster for generating Angular/Spring Boot apps
 
Jcon 2017 How to use Swagger to develop REST applications
Jcon 2017 How to use Swagger to develop REST applicationsJcon 2017 How to use Swagger to develop REST applications
Jcon 2017 How to use Swagger to develop REST applications
 
How to generate a REST CXF3 application from Swagger ApacheConEU 2016
How to generate a REST CXF3 application from Swagger ApacheConEU 2016How to generate a REST CXF3 application from Swagger ApacheConEU 2016
How to generate a REST CXF3 application from Swagger ApacheConEU 2016
 
Introduction to Angular 2
Introduction to Angular 2Introduction to Angular 2
Introduction to Angular 2
 
Building Mobile Friendly APIs in Rails
Building Mobile Friendly APIs in RailsBuilding Mobile Friendly APIs in Rails
Building Mobile Friendly APIs in Rails
 
Docker Enterprise Workshop - Technical
Docker Enterprise Workshop - TechnicalDocker Enterprise Workshop - Technical
Docker Enterprise Workshop - Technical
 
Introduction to google endpoints
Introduction to google endpointsIntroduction to google endpoints
Introduction to google endpoints
 
Google app-engine-with-python
Google app-engine-with-pythonGoogle app-engine-with-python
Google app-engine-with-python
 
WebSDK - Switching between service providers
WebSDK - Switching between service providersWebSDK - Switching between service providers
WebSDK - Switching between service providers
 
REST API 20.2 - Appworks Gateway Integration.pptx
REST API 20.2 - Appworks Gateway Integration.pptxREST API 20.2 - Appworks Gateway Integration.pptx
REST API 20.2 - Appworks Gateway Integration.pptx
 
Angular4 getting started
Angular4 getting startedAngular4 getting started
Angular4 getting started
 
Remote Config REST API and Versioning
Remote Config REST API and VersioningRemote Config REST API and Versioning
Remote Config REST API and Versioning
 
Gatling Performance Workshop
Gatling Performance WorkshopGatling Performance Workshop
Gatling Performance Workshop
 
Parse cloud code
Parse cloud codeParse cloud code
Parse cloud code
 
NetDevOps Development Environments
NetDevOps Development EnvironmentsNetDevOps Development Environments
NetDevOps Development Environments
 
WSO2 Product Release Webinar - WSO2 App Factory 2.1
WSO2 Product Release Webinar - WSO2 App Factory 2.1WSO2 Product Release Webinar - WSO2 App Factory 2.1
WSO2 Product Release Webinar - WSO2 App Factory 2.1
 
JS Fest 2019/Autumn. Влад Федосов. Technology agnostic microservices at SPA f...
JS Fest 2019/Autumn. Влад Федосов. Technology agnostic microservices at SPA f...JS Fest 2019/Autumn. Влад Федосов. Technology agnostic microservices at SPA f...
JS Fest 2019/Autumn. Влад Федосов. Technology agnostic microservices at SPA f...
 
JSFest 2019: Technology agnostic microservices at SPA frontend
JSFest 2019: Technology agnostic microservices at SPA frontendJSFest 2019: Technology agnostic microservices at SPA frontend
JSFest 2019: Technology agnostic microservices at SPA frontend
 
An Overview of Angular 4
An Overview of Angular 4 An Overview of Angular 4
An Overview of Angular 4
 

Kürzlich hochgeladen

Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionSolGuruz
 
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 ...harshavardhanraghave
 
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-learnAmarnathKambale
 
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 TechniquesVictorSzoltysek
 
Exploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdfExploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdfproinshot.com
 
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.pdfVishalKumarJha10
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Steffen Staab
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comFatema Valibhai
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfkalichargn70th171
 
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 AidPhilip Schwarz
 
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.docxComplianceQuest1
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providermohitmore19
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerThousandEyes
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfkalichargn70th171
 
How to Choose the Right Laravel Development Partner in New York City_compress...
How to Choose the Right Laravel Development Partner in New York City_compress...How to Choose the Right Laravel Development Partner in New York City_compress...
How to Choose the Right Laravel Development Partner in New York City_compress...software pro Development
 
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 🔝✔️✔️Delhi Call girls
 
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 studentsHimanshiGarg82
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplatePresentation.STUDIO
 
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 Modelsaagamshah0812
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsJhone kinadey
 

Kürzlich hochgeladen (20)

Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with Precision
 
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 ...
 
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
 
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
 
Exploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdfExploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdf
 
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
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 
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
 
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
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 
How to Choose the Right Laravel Development Partner in New York City_compress...
How to Choose the Right Laravel Development Partner in New York City_compress...How to Choose the Right Laravel Development Partner in New York City_compress...
How to Choose the Right Laravel Development Partner in New York City_compress...
 
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 🔝✔️✔️
 
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
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation Template
 
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
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial Goals
 

Consuming Restful APIs using Swagger v2.0

  • 1. Consuming RESTFul APIs using Swagger v2.0 Pece Nikolovski
  • 2. My Story Can you please provide API Specification for your existing Web Service?
  • 3. THE Web Service specification ● Some .txt or .doc or email containing this... https://my.company.api/v1/login https://my.company.api/v1/user https://my.company.api/v1/cards https://my.company.api/v1/phones https://my.company.api/v1/addresses https://my.company.api/v1/addresses/1
  • 4. THE Web Service specification v2 Push request for login using username, password and deviceId(UUID) https://my.company.api/v1/login Get user details https://my.company.api/v1/user Get list of cards https://my.company.api/v1/cards Get list of phones https://my.company.api/v1/phones •••
  • 5. My approach ● Deciphering phase o Postman ● Document Web Service o Use template doc ● Verify specification docs with client ● Let the coding begin
  • 6. The “Web Service Document”
  • 7. Common issues ● Developers “LOVE” documentation o new api calls o modification of existing o maintenance of Web Service Docs ● Consistency between platforms o iOS, Android and IS ● Etc.
  • 10. What is the meaning of Swagger?
  • 11. What is Swagger? ● Simple representation of your RESTful API ● Group of projects o several main o over 50 community ● http://swagger.io
  • 12. Swagger Spec & Core ● Swagger syntax - Json or Yaml o I prefer Yaml ● Models using JSON Schema draft v4 ● https://github.com/swagger-api/swagger-spec ● https://github.com/swagger-api/swagger-core
  • 13. How to create the Spec? ● Two approaches o Automatic o Manual
  • 15. Outware’s approach ● Why v2.0? o Why not v1.2 or v1.0 ● Lots of reasons… o Java vs Scala ● Works in both cases o building API and client o only client
  • 16. Manually build the Specs ● How to check specs validity? o JSON, YAML, blah blah blah...
  • 17. Swagger Editor ● Available on v2 ● Validation of Swagger syntax ● Visually attractive Online Validator ● Swagger Validator Badge <img src="http://online.swagger.io/validator?url={YOUR_URL}">
  • 18. Swagger UI ● Web Service documentation o Interactive ● Directly test API calls and observe the results
  • 19. Put validation in action ● JSON Schema Validator o https://github.com/ruby-json-schema/json-schema ● Validate models based on spec file
  • 21. Swagger Codegen ● Generate client code based on spec ● Java / Maven project ● Output is auto generated ( & “documented code”) ● Multiple languages support o Language client class o Mustache template files
  • 22. Android - How it works? ● Default setup - Out-Of-The-Box o package, name, artefact id, version ● Run this command: java -jar swagger-codegen-distribution-2.1.0.jar -i http://petstore.swagger.io/v2/swagger.json -l android -o samples/client/petstore/android ● Use generated code as maven dependency in Android project
  • 23. Custom Android example ● Extend AndroidClientCodegen.java o make necessary changes (package, name, version, etc…)
  • 24. Custom Android example ● Re-package using: mvn package ● Generate client code: java -jar swagger-codegen-distribution-2.1.0.jar -i http://petstore.swagger.io/v2/swagger.json -l au.com.outware.MyAndroidCodegen -o samples/client/petstore/android
  • 25. What is the quality of generated code? ● Code as good as your template o Treat as “Black Box” ● Using HTTPRequest ● Errors returned as string instead models ● Minor bugs o array http params o form params
  • 26. What we wanted? ● Retrofit ● OKHttp ● Gradle ● Proper Error Handling ● Javadoc and Sources available in Android project ● Outware’s fork https://github.com/outware-mobile/swagger-codegen
  • 27. How to use? ● Generate Retrofit client java -jar swagger-codegen-distribution-2.1.0.jar -i http://petstore.swagger.io/v2/swagger.json -l android-retrofit -o samples/client/petstore/java
  • 28. How to use? ● Local maven repo: Nexus or Artefactory (to publish .jar artefacts) ● Compile the generated code o gradle build o Jar files in (build/libs/*)  APIs  sources  javadoc ● Publish artefacts o gradle uploadRelease
  • 29. How to use? ● Set as project dependency in build.gradle repositories { maven { url 'http://your_maven_repo' } } ... dependencies { compile 'com.wordnik:io.swagger.client:1.0.0' compile 'com.squareup.retrofit:retrofit:1.8.0' compile 'com.squareup.okhttp:okhttp-urlconnection:2.1.0' compile 'com.squareup.okhttp:okhttp:2.1.0' }
  • 30. iOS - How it works? ● Same as Android ● Default setup - Out-Of-The-Box o generated files prefix ● Run this command: java -jar swagger-codegen-distribution-2.1.0.jar -i http://petstore.swagger.io/v2/swagger.json -l objc -o samples/client/petstore/objc ● Copy generated code and include into project
  • 31. Custom iOS example ● Extend ObjcClientCodegen.java o make changes (file prefix, etc…)
  • 32. Custom iOS example ● Re-package using: mvn package ● Generate client code: java -jar swagger-codegen-distribution-2.1.0.jar -i http://petstore.swagger.io/v2/swagger.json -l au.com.outware.MyObjcCodegen -o samples/client/petstore/objc
  • 33. What we wanted ● AFNetworking v2 ● Project dependency as Podspec o similar approach as with Android target :MyProject do ... pod 'petstore-api' end ● Error Message Handling - instead of returning NSError ● AppleDoc for API calls and models
  • 34. Final piece of the puzzle ● Consistency o versioning o new api spec o updated api spec o bugfixes in templates ● The Web Service Repo o both iOS and Android in same repo ● Automated in CI o one click release
  • 35. Approach Summary ● Design API specs using ‘Swagger Editor’ ● Validate server responses with ‘Ruby JSON Schema Validator’ ● Publish Swagger specs using ‘Swagger UI’ ● Generate client code o One repo for both iOS and Android o Android as Maven dependency o iOS as Podspec dependency ● Update project o Small or Big Refactoring
  • 36. Summary of Issues ● v2 in “development” o Release 2.1.1-M1 on 18 Feb ● Bugs in the template files ● Not yet implemented o Json schema model inheritance not supported o Error model handling o More languages support in v1.2 o Other issues ● Recompiling not efficient o Poorly documented codebase
  • 37. What’s next? ● Contribute to main repo o Command line options ● Auth Support in Swagger o Basic, OAuth v2.0, etc. ● Other new features ● Generating API integration stubs ● And FINALLY...
  • 39. Thank You Pece Nikolovski Outware Mobile - www.outware.com.au The OMPodcast - All about the Mobile Industry

Hinweis der Redaktion

  1. I’m going to talk about a magical way to approach web service APIs
  2. My Story All apps consume some way of a web services Clients have existing web service and want an app This is one of the first questions..
  3. This is what we get... TXT or WORD or even EMAIL More details about the requests?
  4. OK now I know more It’s not their fault So what do I do?
  5. Decipher using Postman - manually hit the endpoints We created a template for documenting APIs Send to client to verify
  6. Here is an example of that doc Great, well documented, devs are happy… But there are issues with this approach… And that is… as you can see, the right alignment of the second table is wrong… I’m joking, here are the common issues with this approach.
  7. Devs LOVE documentation - that is a lie Since we build both iOS and Android consistency is a problem. Changes are not communicated to the other team. So that’s why today I’ll talk about Swagger...
  8. Question is… WHAT IS SWAGGER ---------------------> This is Swagger
  9. Any questions? Thank you all see ya next time
  10. I was not familiar with the meaning of swagger so I’ve looked up in dictionary. Going back to original question...
  11. Simple yet powerful representation of your RESTful API Group of projects with main focus on API documentation (7 main & over 50 community) Impossible to cover all I’ll focus on the ones we use To begin the explanation I want to start with the CORE
  12. It’s a file JSON or YAML Core is parser/generator/validator for the SPEC file Request and response models are represented using JSON Schema V4 Here is an example how the api specs file looks like <show json and explain>
  13. How to create the spec, two main approaches automatic & manual Automatic: Annotate code with swagger documentation to auto generate SPECS Manual: Manually create SPEC using JSON or YAML There are other approaches, dependent on how you build stuff, and which tools you use BUT today I’m going to talk about our approach and what did work for us
  14. First thing to mention is we are focusing only on V2 One reason is that before v2 the tools were build using Scala The project did not get much love and contribution from the community (no one needs another language) The creators came to decision to create V2 in Java Based on my experience so far In most cases we build both Web Service and client mobile app But this approach works even if building just client mobile app Now let’s look at our approach
  15. First thing is to manually create the specification YES, writing json or yaml is not cool at all How is this supposed to help with better understanding of the Web Service It’s more confusion than benefit… That’s why we use tool…
  16. Swagger Editor only available for V2 Offers validation and Visual representation of the spec <Show it in action in browser> Also there is online swagger syntax validator, If you are paranoid about publishing your api, all tools can be hosted locally Setup and deploy in less than 30min
  17. Using the Editor we can make changes but What if you Want to provide UI tool for devs/qa to review and not make changes to the file Interactive web service documentation where you can test and observe the API calls and responses <Show it in action in browser>
  18. Now that we have documentation How do we benefit even more from this specification? What about if we can write tests to validate the server responses if they confirm the specs? Here is how to do that: Since we focus building IS mainly in Ruby... We use Ruby Json Schema validator <explain steps> Load swagger YAML or JSON spec file Grab the response from the server Validate the returned json is compliant to the schema definition
  19. So far we covered how to document and validate the responses We have not mentioned anything about Android or iOS benefits. Well there is more… If we have all API specs why can’t we just generate the code and save time? I present you Swagger Codegen
  20. <Show Android Studio with SwaggerCodegen>
  21. <show example> To start with I’ll cover Android Default package name Default version But what if I want to customize the parameters Maven library from generated code
  22. <show sample java>
  23. Put it this way Treat as black box but devs not happy with code quality and implementation
  24. <show example>
  25. <show sample java>
  26. Join the gang and become a Swagger