SlideShare uma empresa Scribd logo
1 de 46
Baixar para ler offline
HOW TO GENERATE A REST
APPLICATION
@johannes_fiala - DevFestVienna 2016
Agenda
 Generate based on contract
 Extend using code first
 Freeze the contract
 Use the REST API
 Generate client code (Java/Javascript)
 Access with a browser using a UI
 View/Share as HTML/PDF
 Customize the code generator
Toolchain
 Apache CXF 3
 + SwaggerFeature
 + Spring integration/Spring Boot integration
 Swagger-Tools
 Swagger-Editor
 Swagger-Codegen
 Swagger-UI
 Swagger2Markup
Contract first, then code,
then contract …
Complete Process flow
About me…
 Spring REST / Swagger-Springfox
 Added BeanValidation support
 Swagger-Codegen
 Created Javascript client
 Add BeanValidation support for Java
 Improved CXF server (generate complete server)
 Created CXF client
 Swagger2Markup
 Added BeanValidation support
Contract
 WADL (XML-based)
 By w3c, Last update 2009
 Swagger (Json/Yaml-based)
 By Linux foundation
 Version 1.0 – 2011 (Wordnik)
 Version 1.2 - 2014
 Version 2.0 – 2015 / transferred to Linux
foundation / Open-API initiative
 Next version 3.0
 Others: Blueprint, RAML, …
Open API / Swagger
 A language-agnostic interface to REST APIs
 allows to discover and understand the
capabilities of a service
 Supported Formats: JSON/YAML
https://github.com/OAI/OpenAPI-Specification
Contract editors
 Swagger Editor
 by SmartBear
 Eclipse SwagEdit
 By RepreZenAPI Studio
 CommercialTools:
 Restlet Studio
 RepreZenAPI Studio
Swagger-Editor (Json)
Swagger-Editor
 By SmartBear
 Javascript application
 Run locally using npm
 Edit Json /Yaml format
 Generate server
 Generate client
 Import using URL / copy/paste
 Save as Json/Yaml
https://github.com/swagger-api/swagger-editor
Generate the server stub
Swagger-Codegen
 by SmartBear (Apache License)
 Version 2.2.0
 Java program
 Mustache templating
 Generates server + client code
 40+ Supported languages: Java, C#, Javascript,
Dart, Groovy, JaxRS, NodeJS, Objective-C, Perl,
PHP, Python, Ruby, Scala, …
https://github.com/swagger-api/swagger-codegen
Generate the server stub
Swagger-Codegen
 Supported server stubs for Java:
 Java JAX RS
 2.0 spec
 Jersey
 CXF
 Resteasy
 Spring MVC
 Spring Boot
CXF server stub
Features
 Scheduled for version 2.2.2
 Generates Interface/Implementation/Models
 Generate a complete web application
 Context.xml / ApplicationContext.xml
 Web.xml
 Jboss: jboss-web.xml
 Spring Boot support
 Run as Spring-BootApplication
 Run using Spring Integrationtests using random
ports
Swagger-Codegen CLI
 io.swagger.codegen.Codegen
-i hello_world.json
-l jaxrs-cxf
-o c:hello_world_project
-c hello_world_config.json
Swagger-Codegen CLI
Configuration file
Demo
 Create hello world service
 Generate CXF server stub (with Spring
support enabled)
 Run using Spring Boot
 Run Junit-Tests
 Deploy to application server (Jboss EAP 7)
CXF server stub
Supported Features
 Spring application
 Swagger generator
 WADL generator
 BeanValidation annotations
 Activate automatic BeanValidation (1.1)
 Compression (gzip)
 Logging
 Integration-Tests (Spring Boot)
Swagger-Codegen CLI
Display all language options
 io.swagger.codegen.SwaggerCodegen
config-help -l jaxrs-cxf
or
 java -jar modules/swagger-codegen-
cli/target/swagger-codegen-cli.jar config-
help –l jaxrs-cxf
Swagger-Codegen CLI
language options for cxf
Demo
 Re-Generate with more options
 BeanValidation
 Gzip
 Logging
Further development
life cycle
 Extend the API
 code first
 Use the API
 Frontend development
 Finalize: Freeze the contract
Further development
life cycle
Contract
Generate
Code
Add/Modify
Code
Extend the application
 Modify your API:
 Add new services (use JAXRS-annotations)
 Use Swagger annotations
 Use BeanValidation annotations
 Generated Swagger spec gets updated
automatically
Extend the application
Swagger annotations
 Service:
 @Api – activate Swagger for api
 Operations:
 @ApiOperation - description
 @ApiResponse – error codes + return types
 Model:
 @ApiModel - description
 @ApiModelProperty - description
Freeze your API: contract
 Use the updated contract
 Generate interfaces/models
 Prevent accidential changes of the API
 Integrate in build job (Maven / Gradle)
 https://github.com/swagger-api/swagger-
codegen/tree/master/modules/swagger-codegen-maven-plugin
Freeze your API: contract
Demo
 Extend hello world service
(+ BeanValidation)
 Access updated specs
 Swagger spec
 WADL
 Freeze the contract
Use your API
 Generate client stubs
 Swagger-Codegen
 Access your API using a browser
 Swagger-UI
 Generate HTML/PDF documentation
 Swagger2Markup
Swagger-Codegen
 Server + Client code stub generator
 Integration options
 Java application
 Maven
 Gradle
 https://github.com/swagger-api/swagger-codegen
Why generate client code?
 No more manual api calls
 Ensure consistency of your client code with
the API!
 Makes code completion possible!
 Allows developers to read description for
your operations and models in the IDE
 You get compilation errors if the API breaks
with newer versions!
Swagger-UI
 By SmartBear
 Access your API with a browser
 Javascript application
 Can access the generated Swagger spec – always
consistent with your code
 Integration options:
 Copy into your webapp
 load asWeb-Jar
https://github.com/swagger-api/swagger-ui
Swagger-UI
Swagger2Markup
 By Robert Winkler (github)
 Render your API in HTML/PDFs
 Uses Markdown/Asciidoctor files
 Completely customizable
 Integration options:
 Run as Program/Unittest
 Maven
https://github.com/Swagger2Markup/swagger2markup
Swagger2Markup
Swagger
contract
Asciidoctor Html
PDF
Demo
 Client stub generator:
 Java
 Swagger-UI
 Swagger2Markup
Customize the generator
 Generator implemented in Java (one class for
each language)
 Mustache-files
 api.mustache
 apiServiceImpl.mustache
 pojo.mustache
 api_test.mustache
 …
Customize the generator
 Use –t flag for your own templates
 Customize only the templates you need
 Examples:
 Add Maven profile for deployment
 Add logger declaration
 Customize generated unit tests
 …
Customize the generator
 Customize Codegen Languages
 Extend Language class
 Add it to io.swagger.codegen.CodegenConfig
 swagger-codegensrcmainresourcesMETA-
INFservicesio.swagger.codegen.CodegenConfig
 Copy language templates
Demo
 Customize the generator
 E.g. custom pom.xml file for deployment
WADL?
From WADL to Swagger
 Use wadl2java to generate server stub
 BeanValidation: krasa-jaxb-tools
 Activate CXF3 SwaggerFeature
 Use generated Swagger-file
 Will include BeanValidation annotations for
models
CXF Caveats
 Impl: return null = no response in browser
 No JaxRS annotations in Impl. Class
 No @Consumes/@Produces Json will
fallback to default XML
 Jettison on classpath will overrule all other
providers!
Wrapup
 Generate based on contract
 Swagger-Codegen server stubs
 Extend using code first
 CXF 3 Swagger Feature
 Freeze using contract
 Swagger-Codegen build integration (mvn/gradle/cmd)
 Use your application
 Generate client code (Swagger-Codegen)
 Use in browser (Swagger-UI)
 View/Share as HTML/PDF (Swagger2Markup)
 Customize the code generator
Contribute to the projects
 Swagger-Codegen
 Java / JMustache
 Swagger-UI
 Javascript
 Swagger-Editor
 Javascript
 Swagger2Markup
 Java/Asciidoctor
Links & Resources
 Swagger Editor
 http://editor.swagger.io/
 Swagger Codegen
 https://github.com/swagger-api/swagger-codegen
 Swagger UI
 https://github.com/swagger-api/swagger-ui
 CXF
 http://cxf.apache.org/
Thank you for your
attention!
 Demo-Code:
http://github.com/jfiala/swagger-cxf-demo
 Contact:
 @johannes_fiala
 johannes.fiala@fwd.at

Mais conteúdo relacionado

Mais procurados

Document your rest api using swagger - Devoxx 2015
Document your rest api using swagger - Devoxx 2015Document your rest api using swagger - Devoxx 2015
Document your rest api using swagger - Devoxx 2015johannes_fiala
 
Angular based enterprise level frontend architecture
Angular based enterprise level frontend architectureAngular based enterprise level frontend architecture
Angular based enterprise level frontend architectureHimanshu Tamrakar
 
Writer APIs in Java faster with Swagger Inflector
Writer APIs in Java faster with Swagger InflectorWriter APIs in Java faster with Swagger Inflector
Writer APIs in Java faster with Swagger InflectorTony Tam
 
Jenkins and AWS DevOps Tools
Jenkins and AWS DevOps ToolsJenkins and AWS DevOps Tools
Jenkins and AWS DevOps ToolsJimmy Ray
 
Scale your PHP application with Elastic Beanstalk - CloudParty Genova
Scale your PHP application with Elastic Beanstalk - CloudParty GenovaScale your PHP application with Elastic Beanstalk - CloudParty Genova
Scale your PHP application with Elastic Beanstalk - CloudParty GenovaCorley S.r.l.
 
[AnDevCon 2016] Mutation Testing for Android
[AnDevCon 2016] Mutation Testing for Android[AnDevCon 2016] Mutation Testing for Android
[AnDevCon 2016] Mutation Testing for AndroidHazem Saleh
 
Speed up your Web applications with HTML5 WebSockets
Speed up your Web applications with HTML5 WebSocketsSpeed up your Web applications with HTML5 WebSockets
Speed up your Web applications with HTML5 WebSocketsYakov Fain
 
Crystal clear service interfaces w/ Swagger/OpenAPI
Crystal clear service interfaces w/ Swagger/OpenAPICrystal clear service interfaces w/ Swagger/OpenAPI
Crystal clear service interfaces w/ Swagger/OpenAPIScott Triglia
 
Midas - on-the-fly schema migration tool for MongoDB.
Midas - on-the-fly schema migration tool for MongoDB.Midas - on-the-fly schema migration tool for MongoDB.
Midas - on-the-fly schema migration tool for MongoDB.Dhaval Dalal
 
Efficient JavaScript Unit Testing, JavaOne China 2013
Efficient JavaScript Unit Testing, JavaOne China 2013Efficient JavaScript Unit Testing, JavaOne China 2013
Efficient JavaScript Unit Testing, JavaOne China 2013Hazem Saleh
 
Continous UI testing with Espresso and Jenkins
Continous UI testing with Espresso and JenkinsContinous UI testing with Espresso and Jenkins
Continous UI testing with Espresso and JenkinsSylwester Madej
 
Cross-browser testing in the real world
Cross-browser testing in the real worldCross-browser testing in the real world
Cross-browser testing in the real worldMartin Kleppmann
 
How We Built a Mobile Electronic Health Record App Using Xamarin, Angular, an...
How We Built a Mobile Electronic Health Record App Using Xamarin, Angular, an...How We Built a Mobile Electronic Health Record App Using Xamarin, Angular, an...
How We Built a Mobile Electronic Health Record App Using Xamarin, Angular, an...Matt Spradley
 
JavaScript for ABAP Programmers - 4/7 Scope
JavaScript for ABAP Programmers - 4/7 ScopeJavaScript for ABAP Programmers - 4/7 Scope
JavaScript for ABAP Programmers - 4/7 ScopeChris Whealy
 
JavaScript for ABAP Programmers - 1/7 Introduction
JavaScript for ABAP Programmers - 1/7 IntroductionJavaScript for ABAP Programmers - 1/7 Introduction
JavaScript for ABAP Programmers - 1/7 IntroductionChris Whealy
 
Introduction to Codenvy / JugSummerCamp 2014
Introduction to Codenvy / JugSummerCamp 2014Introduction to Codenvy / JugSummerCamp 2014
Introduction to Codenvy / JugSummerCamp 2014Florent BENOIT
 

Mais procurados (19)

Document your rest api using swagger - Devoxx 2015
Document your rest api using swagger - Devoxx 2015Document your rest api using swagger - Devoxx 2015
Document your rest api using swagger - Devoxx 2015
 
Angular based enterprise level frontend architecture
Angular based enterprise level frontend architectureAngular based enterprise level frontend architecture
Angular based enterprise level frontend architecture
 
Writer APIs in Java faster with Swagger Inflector
Writer APIs in Java faster with Swagger InflectorWriter APIs in Java faster with Swagger Inflector
Writer APIs in Java faster with Swagger Inflector
 
Jenkins and AWS DevOps Tools
Jenkins and AWS DevOps ToolsJenkins and AWS DevOps Tools
Jenkins and AWS DevOps Tools
 
Scale your PHP application with Elastic Beanstalk - CloudParty Genova
Scale your PHP application with Elastic Beanstalk - CloudParty GenovaScale your PHP application with Elastic Beanstalk - CloudParty Genova
Scale your PHP application with Elastic Beanstalk - CloudParty Genova
 
Hands on the gradle
Hands on the gradleHands on the gradle
Hands on the gradle
 
[AnDevCon 2016] Mutation Testing for Android
[AnDevCon 2016] Mutation Testing for Android[AnDevCon 2016] Mutation Testing for Android
[AnDevCon 2016] Mutation Testing for Android
 
Xamarin - Beyond the Basics
Xamarin - Beyond the BasicsXamarin - Beyond the Basics
Xamarin - Beyond the Basics
 
Speed up your Web applications with HTML5 WebSockets
Speed up your Web applications with HTML5 WebSocketsSpeed up your Web applications with HTML5 WebSockets
Speed up your Web applications with HTML5 WebSockets
 
Crystal clear service interfaces w/ Swagger/OpenAPI
Crystal clear service interfaces w/ Swagger/OpenAPICrystal clear service interfaces w/ Swagger/OpenAPI
Crystal clear service interfaces w/ Swagger/OpenAPI
 
Midas - on-the-fly schema migration tool for MongoDB.
Midas - on-the-fly schema migration tool for MongoDB.Midas - on-the-fly schema migration tool for MongoDB.
Midas - on-the-fly schema migration tool for MongoDB.
 
Efficient JavaScript Unit Testing, JavaOne China 2013
Efficient JavaScript Unit Testing, JavaOne China 2013Efficient JavaScript Unit Testing, JavaOne China 2013
Efficient JavaScript Unit Testing, JavaOne China 2013
 
Continous UI testing with Espresso and Jenkins
Continous UI testing with Espresso and JenkinsContinous UI testing with Espresso and Jenkins
Continous UI testing with Espresso and Jenkins
 
Cross-browser testing in the real world
Cross-browser testing in the real worldCross-browser testing in the real world
Cross-browser testing in the real world
 
How We Built a Mobile Electronic Health Record App Using Xamarin, Angular, an...
How We Built a Mobile Electronic Health Record App Using Xamarin, Angular, an...How We Built a Mobile Electronic Health Record App Using Xamarin, Angular, an...
How We Built a Mobile Electronic Health Record App Using Xamarin, Angular, an...
 
JavaScript for ABAP Programmers - 4/7 Scope
JavaScript for ABAP Programmers - 4/7 ScopeJavaScript for ABAP Programmers - 4/7 Scope
JavaScript for ABAP Programmers - 4/7 Scope
 
JavaScript for ABAP Programmers - 1/7 Introduction
JavaScript for ABAP Programmers - 1/7 IntroductionJavaScript for ABAP Programmers - 1/7 Introduction
JavaScript for ABAP Programmers - 1/7 Introduction
 
Introduction to Codenvy / JugSummerCamp 2014
Introduction to Codenvy / JugSummerCamp 2014Introduction to Codenvy / JugSummerCamp 2014
Introduction to Codenvy / JugSummerCamp 2014
 
Android CI and Appium
Android CI and AppiumAndroid CI and Appium
Android CI and Appium
 

Destaque

Swagger 2.0: Latest and Greatest
Swagger 2.0: Latest and GreatestSwagger 2.0: Latest and Greatest
Swagger 2.0: Latest and GreatestLaunchAny
 
The Java Microservice Library
The Java Microservice LibraryThe Java Microservice Library
The Java Microservice LibraryRick Hightower
 
Enhance existing REST APIs (e.g. Facebook Graph API) with code completion us...
Enhance existing REST APIs  (e.g. Facebook Graph API) with code completion us...Enhance existing REST APIs  (e.g. Facebook Graph API) with code completion us...
Enhance existing REST APIs (e.g. Facebook Graph API) with code completion us...johannes_fiala
 
Consumer Driven Contracts and Your Microservice Architecture @ Warsaw JUG
Consumer Driven Contracts and Your Microservice Architecture @ Warsaw JUGConsumer Driven Contracts and Your Microservice Architecture @ Warsaw JUG
Consumer Driven Contracts and Your Microservice Architecture @ Warsaw JUGMarcin Grzejszczak
 
Swagger - make your API accessible
Swagger - make your API accessibleSwagger - make your API accessible
Swagger - make your API accessibleVictor Trakhtenberg
 
Spring Cloud Contract And Your Microservice Architecture
Spring Cloud Contract And Your Microservice ArchitectureSpring Cloud Contract And Your Microservice Architecture
Spring Cloud Contract And Your Microservice ArchitectureMarcin Grzejszczak
 
Building REST APIs with Spring Boot and Spring Cloud
Building REST APIs with Spring Boot and Spring CloudBuilding REST APIs with Spring Boot and Spring Cloud
Building REST APIs with Spring Boot and Spring CloudKenny Bastani
 
Consumer Driven Contracts and Your Microservice Architecture
Consumer Driven Contracts and Your Microservice ArchitectureConsumer Driven Contracts and Your Microservice Architecture
Consumer Driven Contracts and Your Microservice ArchitectureMarcin Grzejszczak
 
API Developer Experience: Why it Matters, and How Documenting Your API with S...
API Developer Experience: Why it Matters, and How Documenting Your API with S...API Developer Experience: Why it Matters, and How Documenting Your API with S...
API Developer Experience: Why it Matters, and How Documenting Your API with S...SmartBear
 
Swagger pour documenter votre REST API - présentation en français
Swagger pour documenter votre REST API - présentation en françaisSwagger pour documenter votre REST API - présentation en français
Swagger pour documenter votre REST API - présentation en françaisMartin Yung
 
Microservices Tracing With Spring Cloud and Zipkin @Szczecin JUG
Microservices Tracing With Spring Cloud and Zipkin @Szczecin JUGMicroservices Tracing With Spring Cloud and Zipkin @Szczecin JUG
Microservices Tracing With Spring Cloud and Zipkin @Szczecin JUGMarcin Grzejszczak
 
Swagger, language pour décrire des API REST
Swagger, language pour décrire des API RESTSwagger, language pour décrire des API REST
Swagger, language pour décrire des API RESTPierre-André Vullioud
 

Destaque (12)

Swagger 2.0: Latest and Greatest
Swagger 2.0: Latest and GreatestSwagger 2.0: Latest and Greatest
Swagger 2.0: Latest and Greatest
 
The Java Microservice Library
The Java Microservice LibraryThe Java Microservice Library
The Java Microservice Library
 
Enhance existing REST APIs (e.g. Facebook Graph API) with code completion us...
Enhance existing REST APIs  (e.g. Facebook Graph API) with code completion us...Enhance existing REST APIs  (e.g. Facebook Graph API) with code completion us...
Enhance existing REST APIs (e.g. Facebook Graph API) with code completion us...
 
Consumer Driven Contracts and Your Microservice Architecture @ Warsaw JUG
Consumer Driven Contracts and Your Microservice Architecture @ Warsaw JUGConsumer Driven Contracts and Your Microservice Architecture @ Warsaw JUG
Consumer Driven Contracts and Your Microservice Architecture @ Warsaw JUG
 
Swagger - make your API accessible
Swagger - make your API accessibleSwagger - make your API accessible
Swagger - make your API accessible
 
Spring Cloud Contract And Your Microservice Architecture
Spring Cloud Contract And Your Microservice ArchitectureSpring Cloud Contract And Your Microservice Architecture
Spring Cloud Contract And Your Microservice Architecture
 
Building REST APIs with Spring Boot and Spring Cloud
Building REST APIs with Spring Boot and Spring CloudBuilding REST APIs with Spring Boot and Spring Cloud
Building REST APIs with Spring Boot and Spring Cloud
 
Consumer Driven Contracts and Your Microservice Architecture
Consumer Driven Contracts and Your Microservice ArchitectureConsumer Driven Contracts and Your Microservice Architecture
Consumer Driven Contracts and Your Microservice Architecture
 
API Developer Experience: Why it Matters, and How Documenting Your API with S...
API Developer Experience: Why it Matters, and How Documenting Your API with S...API Developer Experience: Why it Matters, and How Documenting Your API with S...
API Developer Experience: Why it Matters, and How Documenting Your API with S...
 
Swagger pour documenter votre REST API - présentation en français
Swagger pour documenter votre REST API - présentation en françaisSwagger pour documenter votre REST API - présentation en français
Swagger pour documenter votre REST API - présentation en français
 
Microservices Tracing With Spring Cloud and Zipkin @Szczecin JUG
Microservices Tracing With Spring Cloud and Zipkin @Szczecin JUGMicroservices Tracing With Spring Cloud and Zipkin @Szczecin JUG
Microservices Tracing With Spring Cloud and Zipkin @Szczecin JUG
 
Swagger, language pour décrire des API REST
Swagger, language pour décrire des API RESTSwagger, language pour décrire des API REST
Swagger, language pour décrire des API REST
 

Semelhante a How to generate a rest application - DevFest Vienna 2016

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
 
Application Lifecycle Management in a Serverless World
Application Lifecycle Management in a Serverless WorldApplication Lifecycle Management in a Serverless World
Application Lifecycle Management in a Serverless WorldAmazon Web Services
 
Consuming Restful APIs using Swagger v2.0
Consuming Restful APIs using Swagger v2.0Consuming Restful APIs using Swagger v2.0
Consuming Restful APIs using Swagger v2.0Pece Nikolovski
 
Amazon API Gateway
Amazon API GatewayAmazon API Gateway
Amazon API GatewayMark Bate
 
Google Web Toolkit Introduction - eXo Platform SEA
Google Web Toolkit Introduction - eXo Platform SEAGoogle Web Toolkit Introduction - eXo Platform SEA
Google Web Toolkit Introduction - eXo Platform SEAnerazz08
 
Spring Surf Development Tools
Spring Surf Development ToolsSpring Surf Development Tools
Spring Surf Development ToolsAlfresco Software
 
Amazon API Gateway
Amazon API GatewayAmazon API Gateway
Amazon API GatewayMark Bate
 
Introduction to google endpoints
Introduction to google endpointsIntroduction to google endpoints
Introduction to google endpointsShinto Anto
 
Vijay Oscon
Vijay OsconVijay Oscon
Vijay Osconvijayrvr
 
Gwt session
Gwt sessionGwt session
Gwt sessionMans Jug
 
Serverless on Azure with Functions
Serverless on Azure with FunctionsServerless on Azure with Functions
Serverless on Azure with FunctionsChristos Matskas
 
Web API or WCF - An Architectural Comparison
Web API or WCF - An Architectural ComparisonWeb API or WCF - An Architectural Comparison
Web API or WCF - An Architectural ComparisonAdnan Masood
 
Real time Communication with Signalr (Android Client)
Real time Communication with Signalr (Android Client)Real time Communication with Signalr (Android Client)
Real time Communication with Signalr (Android Client)Deepak Gupta
 
Ajax toolkit framework
Ajax toolkit frameworkAjax toolkit framework
Ajax toolkit frameworkSunil Kumar
 
Best of Microsoft Dev Camp 2015
Best of Microsoft Dev Camp 2015Best of Microsoft Dev Camp 2015
Best of Microsoft Dev Camp 2015Bluegrass Digital
 

Semelhante a How to generate a rest application - DevFest Vienna 2016 (20)

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
 
Application Lifecycle Management in a Serverless World
Application Lifecycle Management in a Serverless WorldApplication Lifecycle Management in a Serverless World
Application Lifecycle Management in a Serverless World
 
Deep Dive on Serverless Stack
Deep Dive on Serverless StackDeep Dive on Serverless Stack
Deep Dive on Serverless Stack
 
Consuming Restful APIs using Swagger v2.0
Consuming Restful APIs using Swagger v2.0Consuming Restful APIs using Swagger v2.0
Consuming Restful APIs using Swagger v2.0
 
Amazon API Gateway
Amazon API GatewayAmazon API Gateway
Amazon API Gateway
 
Google Web Toolkit Introduction - eXo Platform SEA
Google Web Toolkit Introduction - eXo Platform SEAGoogle Web Toolkit Introduction - eXo Platform SEA
Google Web Toolkit Introduction - eXo Platform SEA
 
Spring Surf Development Tools
Spring Surf Development ToolsSpring Surf Development Tools
Spring Surf Development Tools
 
Amazon API Gateway
Amazon API GatewayAmazon API Gateway
Amazon API Gateway
 
Introduction to google endpoints
Introduction to google endpointsIntroduction to google endpoints
Introduction to google endpoints
 
RIA / SPA with ASP.NET
RIA / SPA with ASP.NETRIA / SPA with ASP.NET
RIA / SPA with ASP.NET
 
Vijay Oscon
Vijay OsconVijay Oscon
Vijay Oscon
 
AWS Code Services
AWS Code ServicesAWS Code Services
AWS Code Services
 
Gwt session
Gwt sessionGwt session
Gwt session
 
Gwt session
Gwt sessionGwt session
Gwt session
 
Serverless on Azure with Functions
Serverless on Azure with FunctionsServerless on Azure with Functions
Serverless on Azure with Functions
 
Web API or WCF - An Architectural Comparison
Web API or WCF - An Architectural ComparisonWeb API or WCF - An Architectural Comparison
Web API or WCF - An Architectural Comparison
 
Real time Communication with Signalr (Android Client)
Real time Communication with Signalr (Android Client)Real time Communication with Signalr (Android Client)
Real time Communication with Signalr (Android Client)
 
Ajax toolkit framework
Ajax toolkit frameworkAjax toolkit framework
Ajax toolkit framework
 
Best of Microsoft Dev Camp 2015
Best of Microsoft Dev Camp 2015Best of Microsoft Dev Camp 2015
Best of Microsoft Dev Camp 2015
 

Último

Designing A Time bound resource download URL
Designing A Time bound resource download URLDesigning A Time bound resource download URL
Designing A Time bound resource download URLRuncy Oommen
 
AI You Can Trust - Ensuring Success with Data Integrity Webinar
AI You Can Trust - Ensuring Success with Data Integrity WebinarAI You Can Trust - Ensuring Success with Data Integrity Webinar
AI You Can Trust - Ensuring Success with Data Integrity WebinarPrecisely
 
NIST Cybersecurity Framework (CSF) 2.0 Workshop
NIST Cybersecurity Framework (CSF) 2.0 WorkshopNIST Cybersecurity Framework (CSF) 2.0 Workshop
NIST Cybersecurity Framework (CSF) 2.0 WorkshopBachir Benyammi
 
Building Your Own AI Instance (TBLC AI )
Building Your Own AI Instance (TBLC AI )Building Your Own AI Instance (TBLC AI )
Building Your Own AI Instance (TBLC AI )Brian Pichman
 
COMPUTER 10 Lesson 8 - Building a Website
COMPUTER 10 Lesson 8 - Building a WebsiteCOMPUTER 10 Lesson 8 - Building a Website
COMPUTER 10 Lesson 8 - Building a Websitedgelyza
 
Building AI-Driven Apps Using Semantic Kernel.pptx
Building AI-Driven Apps Using Semantic Kernel.pptxBuilding AI-Driven Apps Using Semantic Kernel.pptx
Building AI-Driven Apps Using Semantic Kernel.pptxUdaiappa Ramachandran
 
20230202 - Introduction to tis-py
20230202 - Introduction to tis-py20230202 - Introduction to tis-py
20230202 - Introduction to tis-pyJamie (Taka) Wang
 
UWB Technology for Enhanced Indoor and Outdoor Positioning in Physiological M...
UWB Technology for Enhanced Indoor and Outdoor Positioning in Physiological M...UWB Technology for Enhanced Indoor and Outdoor Positioning in Physiological M...
UWB Technology for Enhanced Indoor and Outdoor Positioning in Physiological M...UbiTrack UK
 
How Accurate are Carbon Emissions Projections?
How Accurate are Carbon Emissions Projections?How Accurate are Carbon Emissions Projections?
How Accurate are Carbon Emissions Projections?IES VE
 
Linked Data in Production: Moving Beyond Ontologies
Linked Data in Production: Moving Beyond OntologiesLinked Data in Production: Moving Beyond Ontologies
Linked Data in Production: Moving Beyond OntologiesDavid Newbury
 
Using IESVE for Loads, Sizing and Heat Pump Modeling to Achieve Decarbonization
Using IESVE for Loads, Sizing and Heat Pump Modeling to Achieve DecarbonizationUsing IESVE for Loads, Sizing and Heat Pump Modeling to Achieve Decarbonization
Using IESVE for Loads, Sizing and Heat Pump Modeling to Achieve DecarbonizationIES VE
 
Artificial Intelligence & SEO Trends for 2024
Artificial Intelligence & SEO Trends for 2024Artificial Intelligence & SEO Trends for 2024
Artificial Intelligence & SEO Trends for 2024D Cloud Solutions
 
UiPath Studio Web workshop series - Day 6
UiPath Studio Web workshop series - Day 6UiPath Studio Web workshop series - Day 6
UiPath Studio Web workshop series - Day 6DianaGray10
 
activity_diagram_combine_v4_20190827.pdfactivity_diagram_combine_v4_20190827.pdf
activity_diagram_combine_v4_20190827.pdfactivity_diagram_combine_v4_20190827.pdfactivity_diagram_combine_v4_20190827.pdfactivity_diagram_combine_v4_20190827.pdf
activity_diagram_combine_v4_20190827.pdfactivity_diagram_combine_v4_20190827.pdfJamie (Taka) Wang
 
COMPUTER 10: Lesson 7 - File Storage and Online Collaboration
COMPUTER 10: Lesson 7 - File Storage and Online CollaborationCOMPUTER 10: Lesson 7 - File Storage and Online Collaboration
COMPUTER 10: Lesson 7 - File Storage and Online Collaborationbruanjhuli
 
Secure your environment with UiPath and CyberArk technologies - Session 1
Secure your environment with UiPath and CyberArk technologies - Session 1Secure your environment with UiPath and CyberArk technologies - Session 1
Secure your environment with UiPath and CyberArk technologies - Session 1DianaGray10
 
Videogame localization & technology_ how to enhance the power of translation.pdf
Videogame localization & technology_ how to enhance the power of translation.pdfVideogame localization & technology_ how to enhance the power of translation.pdf
Videogame localization & technology_ how to enhance the power of translation.pdfinfogdgmi
 
UiPath Studio Web workshop series - Day 8
UiPath Studio Web workshop series - Day 8UiPath Studio Web workshop series - Day 8
UiPath Studio Web workshop series - Day 8DianaGray10
 
Bird eye's view on Camunda open source ecosystem
Bird eye's view on Camunda open source ecosystemBird eye's view on Camunda open source ecosystem
Bird eye's view on Camunda open source ecosystemAsko Soukka
 

Último (20)

Designing A Time bound resource download URL
Designing A Time bound resource download URLDesigning A Time bound resource download URL
Designing A Time bound resource download URL
 
AI You Can Trust - Ensuring Success with Data Integrity Webinar
AI You Can Trust - Ensuring Success with Data Integrity WebinarAI You Can Trust - Ensuring Success with Data Integrity Webinar
AI You Can Trust - Ensuring Success with Data Integrity Webinar
 
NIST Cybersecurity Framework (CSF) 2.0 Workshop
NIST Cybersecurity Framework (CSF) 2.0 WorkshopNIST Cybersecurity Framework (CSF) 2.0 Workshop
NIST Cybersecurity Framework (CSF) 2.0 Workshop
 
Building Your Own AI Instance (TBLC AI )
Building Your Own AI Instance (TBLC AI )Building Your Own AI Instance (TBLC AI )
Building Your Own AI Instance (TBLC AI )
 
COMPUTER 10 Lesson 8 - Building a Website
COMPUTER 10 Lesson 8 - Building a WebsiteCOMPUTER 10 Lesson 8 - Building a Website
COMPUTER 10 Lesson 8 - Building a Website
 
Building AI-Driven Apps Using Semantic Kernel.pptx
Building AI-Driven Apps Using Semantic Kernel.pptxBuilding AI-Driven Apps Using Semantic Kernel.pptx
Building AI-Driven Apps Using Semantic Kernel.pptx
 
20230202 - Introduction to tis-py
20230202 - Introduction to tis-py20230202 - Introduction to tis-py
20230202 - Introduction to tis-py
 
UWB Technology for Enhanced Indoor and Outdoor Positioning in Physiological M...
UWB Technology for Enhanced Indoor and Outdoor Positioning in Physiological M...UWB Technology for Enhanced Indoor and Outdoor Positioning in Physiological M...
UWB Technology for Enhanced Indoor and Outdoor Positioning in Physiological M...
 
How Accurate are Carbon Emissions Projections?
How Accurate are Carbon Emissions Projections?How Accurate are Carbon Emissions Projections?
How Accurate are Carbon Emissions Projections?
 
Linked Data in Production: Moving Beyond Ontologies
Linked Data in Production: Moving Beyond OntologiesLinked Data in Production: Moving Beyond Ontologies
Linked Data in Production: Moving Beyond Ontologies
 
Using IESVE for Loads, Sizing and Heat Pump Modeling to Achieve Decarbonization
Using IESVE for Loads, Sizing and Heat Pump Modeling to Achieve DecarbonizationUsing IESVE for Loads, Sizing and Heat Pump Modeling to Achieve Decarbonization
Using IESVE for Loads, Sizing and Heat Pump Modeling to Achieve Decarbonization
 
Artificial Intelligence & SEO Trends for 2024
Artificial Intelligence & SEO Trends for 2024Artificial Intelligence & SEO Trends for 2024
Artificial Intelligence & SEO Trends for 2024
 
UiPath Studio Web workshop series - Day 6
UiPath Studio Web workshop series - Day 6UiPath Studio Web workshop series - Day 6
UiPath Studio Web workshop series - Day 6
 
activity_diagram_combine_v4_20190827.pdfactivity_diagram_combine_v4_20190827.pdf
activity_diagram_combine_v4_20190827.pdfactivity_diagram_combine_v4_20190827.pdfactivity_diagram_combine_v4_20190827.pdfactivity_diagram_combine_v4_20190827.pdf
activity_diagram_combine_v4_20190827.pdfactivity_diagram_combine_v4_20190827.pdf
 
COMPUTER 10: Lesson 7 - File Storage and Online Collaboration
COMPUTER 10: Lesson 7 - File Storage and Online CollaborationCOMPUTER 10: Lesson 7 - File Storage and Online Collaboration
COMPUTER 10: Lesson 7 - File Storage and Online Collaboration
 
Secure your environment with UiPath and CyberArk technologies - Session 1
Secure your environment with UiPath and CyberArk technologies - Session 1Secure your environment with UiPath and CyberArk technologies - Session 1
Secure your environment with UiPath and CyberArk technologies - Session 1
 
Videogame localization & technology_ how to enhance the power of translation.pdf
Videogame localization & technology_ how to enhance the power of translation.pdfVideogame localization & technology_ how to enhance the power of translation.pdf
Videogame localization & technology_ how to enhance the power of translation.pdf
 
20150722 - AGV
20150722 - AGV20150722 - AGV
20150722 - AGV
 
UiPath Studio Web workshop series - Day 8
UiPath Studio Web workshop series - Day 8UiPath Studio Web workshop series - Day 8
UiPath Studio Web workshop series - Day 8
 
Bird eye's view on Camunda open source ecosystem
Bird eye's view on Camunda open source ecosystemBird eye's view on Camunda open source ecosystem
Bird eye's view on Camunda open source ecosystem
 

How to generate a rest application - DevFest Vienna 2016

  • 1. HOW TO GENERATE A REST APPLICATION @johannes_fiala - DevFestVienna 2016
  • 2. Agenda  Generate based on contract  Extend using code first  Freeze the contract  Use the REST API  Generate client code (Java/Javascript)  Access with a browser using a UI  View/Share as HTML/PDF  Customize the code generator
  • 3. Toolchain  Apache CXF 3  + SwaggerFeature  + Spring integration/Spring Boot integration  Swagger-Tools  Swagger-Editor  Swagger-Codegen  Swagger-UI  Swagger2Markup
  • 4. Contract first, then code, then contract …
  • 6. About me…  Spring REST / Swagger-Springfox  Added BeanValidation support  Swagger-Codegen  Created Javascript client  Add BeanValidation support for Java  Improved CXF server (generate complete server)  Created CXF client  Swagger2Markup  Added BeanValidation support
  • 7. Contract  WADL (XML-based)  By w3c, Last update 2009  Swagger (Json/Yaml-based)  By Linux foundation  Version 1.0 – 2011 (Wordnik)  Version 1.2 - 2014  Version 2.0 – 2015 / transferred to Linux foundation / Open-API initiative  Next version 3.0  Others: Blueprint, RAML, …
  • 8. Open API / Swagger  A language-agnostic interface to REST APIs  allows to discover and understand the capabilities of a service  Supported Formats: JSON/YAML https://github.com/OAI/OpenAPI-Specification
  • 9. Contract editors  Swagger Editor  by SmartBear  Eclipse SwagEdit  By RepreZenAPI Studio  CommercialTools:  Restlet Studio  RepreZenAPI Studio
  • 11. Swagger-Editor  By SmartBear  Javascript application  Run locally using npm  Edit Json /Yaml format  Generate server  Generate client  Import using URL / copy/paste  Save as Json/Yaml https://github.com/swagger-api/swagger-editor
  • 12. Generate the server stub Swagger-Codegen  by SmartBear (Apache License)  Version 2.2.0  Java program  Mustache templating  Generates server + client code  40+ Supported languages: Java, C#, Javascript, Dart, Groovy, JaxRS, NodeJS, Objective-C, Perl, PHP, Python, Ruby, Scala, … https://github.com/swagger-api/swagger-codegen
  • 13. Generate the server stub Swagger-Codegen  Supported server stubs for Java:  Java JAX RS  2.0 spec  Jersey  CXF  Resteasy  Spring MVC  Spring Boot
  • 14. CXF server stub Features  Scheduled for version 2.2.2  Generates Interface/Implementation/Models  Generate a complete web application  Context.xml / ApplicationContext.xml  Web.xml  Jboss: jboss-web.xml  Spring Boot support  Run as Spring-BootApplication  Run using Spring Integrationtests using random ports
  • 15. Swagger-Codegen CLI  io.swagger.codegen.Codegen -i hello_world.json -l jaxrs-cxf -o c:hello_world_project -c hello_world_config.json
  • 17. Demo  Create hello world service  Generate CXF server stub (with Spring support enabled)  Run using Spring Boot  Run Junit-Tests  Deploy to application server (Jboss EAP 7)
  • 18. CXF server stub Supported Features  Spring application  Swagger generator  WADL generator  BeanValidation annotations  Activate automatic BeanValidation (1.1)  Compression (gzip)  Logging  Integration-Tests (Spring Boot)
  • 19. Swagger-Codegen CLI Display all language options  io.swagger.codegen.SwaggerCodegen config-help -l jaxrs-cxf or  java -jar modules/swagger-codegen- cli/target/swagger-codegen-cli.jar config- help –l jaxrs-cxf
  • 21. Demo  Re-Generate with more options  BeanValidation  Gzip  Logging
  • 22. Further development life cycle  Extend the API  code first  Use the API  Frontend development  Finalize: Freeze the contract
  • 24. Extend the application  Modify your API:  Add new services (use JAXRS-annotations)  Use Swagger annotations  Use BeanValidation annotations  Generated Swagger spec gets updated automatically
  • 25. Extend the application Swagger annotations  Service:  @Api – activate Swagger for api  Operations:  @ApiOperation - description  @ApiResponse – error codes + return types  Model:  @ApiModel - description  @ApiModelProperty - description
  • 26. Freeze your API: contract  Use the updated contract  Generate interfaces/models  Prevent accidential changes of the API  Integrate in build job (Maven / Gradle)  https://github.com/swagger-api/swagger- codegen/tree/master/modules/swagger-codegen-maven-plugin
  • 27. Freeze your API: contract
  • 28. Demo  Extend hello world service (+ BeanValidation)  Access updated specs  Swagger spec  WADL  Freeze the contract
  • 29. Use your API  Generate client stubs  Swagger-Codegen  Access your API using a browser  Swagger-UI  Generate HTML/PDF documentation  Swagger2Markup
  • 30. Swagger-Codegen  Server + Client code stub generator  Integration options  Java application  Maven  Gradle  https://github.com/swagger-api/swagger-codegen
  • 31. Why generate client code?  No more manual api calls  Ensure consistency of your client code with the API!  Makes code completion possible!  Allows developers to read description for your operations and models in the IDE  You get compilation errors if the API breaks with newer versions!
  • 32. Swagger-UI  By SmartBear  Access your API with a browser  Javascript application  Can access the generated Swagger spec – always consistent with your code  Integration options:  Copy into your webapp  load asWeb-Jar https://github.com/swagger-api/swagger-ui
  • 34. Swagger2Markup  By Robert Winkler (github)  Render your API in HTML/PDFs  Uses Markdown/Asciidoctor files  Completely customizable  Integration options:  Run as Program/Unittest  Maven https://github.com/Swagger2Markup/swagger2markup
  • 36. Demo  Client stub generator:  Java  Swagger-UI  Swagger2Markup
  • 37. Customize the generator  Generator implemented in Java (one class for each language)  Mustache-files  api.mustache  apiServiceImpl.mustache  pojo.mustache  api_test.mustache  …
  • 38. Customize the generator  Use –t flag for your own templates  Customize only the templates you need  Examples:  Add Maven profile for deployment  Add logger declaration  Customize generated unit tests  …
  • 39. Customize the generator  Customize Codegen Languages  Extend Language class  Add it to io.swagger.codegen.CodegenConfig  swagger-codegensrcmainresourcesMETA- INFservicesio.swagger.codegen.CodegenConfig  Copy language templates
  • 40. Demo  Customize the generator  E.g. custom pom.xml file for deployment
  • 41. WADL? From WADL to Swagger  Use wadl2java to generate server stub  BeanValidation: krasa-jaxb-tools  Activate CXF3 SwaggerFeature  Use generated Swagger-file  Will include BeanValidation annotations for models
  • 42. CXF Caveats  Impl: return null = no response in browser  No JaxRS annotations in Impl. Class  No @Consumes/@Produces Json will fallback to default XML  Jettison on classpath will overrule all other providers!
  • 43. Wrapup  Generate based on contract  Swagger-Codegen server stubs  Extend using code first  CXF 3 Swagger Feature  Freeze using contract  Swagger-Codegen build integration (mvn/gradle/cmd)  Use your application  Generate client code (Swagger-Codegen)  Use in browser (Swagger-UI)  View/Share as HTML/PDF (Swagger2Markup)  Customize the code generator
  • 44. Contribute to the projects  Swagger-Codegen  Java / JMustache  Swagger-UI  Javascript  Swagger-Editor  Javascript  Swagger2Markup  Java/Asciidoctor
  • 45. Links & Resources  Swagger Editor  http://editor.swagger.io/  Swagger Codegen  https://github.com/swagger-api/swagger-codegen  Swagger UI  https://github.com/swagger-api/swagger-ui  CXF  http://cxf.apache.org/
  • 46. Thank you for your attention!  Demo-Code: http://github.com/jfiala/swagger-cxf-demo  Contact:  @johannes_fiala  johannes.fiala@fwd.at

Notas do Editor

  1. Ask for usage?