SlideShare a Scribd company logo
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

More Related Content

What's hot

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
johannes_fiala
 
Angular based enterprise level frontend architecture
Angular based enterprise level frontend architectureAngular based enterprise level frontend architecture
Angular based enterprise level frontend architecture
Himanshu 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 Inflector
Tony Tam
 
Jenkins and AWS DevOps Tools
Jenkins and AWS DevOps ToolsJenkins and AWS DevOps Tools
Jenkins and AWS DevOps Tools
Jimmy 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 Genova
Corley S.r.l.
 
Hands on the gradle
Hands on the gradleHands on the gradle
Hands on the gradle
Kostiantyn Zghirovskyi
 
[AnDevCon 2016] Mutation Testing for Android
[AnDevCon 2016] Mutation Testing for Android[AnDevCon 2016] Mutation Testing for Android
[AnDevCon 2016] Mutation Testing for Android
Hazem Saleh
 
Xamarin - Beyond the Basics
Xamarin - Beyond the BasicsXamarin - Beyond the Basics
Xamarin - Beyond the Basics
Prabha Kularathna
 
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
Yakov 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/OpenAPI
Scott 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 2013
Hazem 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 Jenkins
Sylwester 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 world
Martin 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 Scope
Chris 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 Introduction
Chris Whealy
 
Introduction to Codenvy / JugSummerCamp 2014
Introduction to Codenvy / JugSummerCamp 2014Introduction to Codenvy / JugSummerCamp 2014
Introduction to Codenvy / JugSummerCamp 2014
Florent BENOIT
 
Android CI and Appium
Android CI and AppiumAndroid CI and Appium
Android CI and Appium
Oren Ashkenazy
 

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

Viewers also liked

Swagger 2.0: Latest and Greatest
Swagger 2.0: Latest and GreatestSwagger 2.0: Latest and Greatest
Swagger 2.0: Latest and Greatest
LaunchAny
 
The Java Microservice Library
The Java Microservice LibraryThe Java Microservice Library
The Java Microservice Library
Rick 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 JUG
Marcin Grzejszczak
 
Swagger - make your API accessible
Swagger - make your API accessibleSwagger - make your API accessible
Swagger - make your API accessible
Victor 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 Architecture
Marcin 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 Cloud
Kenny 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 Architecture
Marcin 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çais
Martin 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 JUG
Marcin 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 REST
Pierre-André Vullioud
 

Viewers also liked (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
 

Similar to 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 applications
johannes_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 2016
johannes_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 World
Amazon Web Services
 
Deep Dive on Serverless Stack
Deep Dive on Serverless StackDeep Dive on Serverless Stack
Deep Dive on Serverless Stack
Amazon 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.0
Pece Nikolovski
 
Amazon API Gateway
Amazon API GatewayAmazon API Gateway
Amazon API Gateway
Mark 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 SEA
nerazz08
 
Spring Surf Development Tools
Spring Surf Development ToolsSpring Surf Development Tools
Spring Surf Development Tools
Alfresco Software
 
Amazon API Gateway
Amazon API GatewayAmazon API Gateway
Amazon API Gateway
Mark Bate
 
Introduction to google endpoints
Introduction to google endpointsIntroduction to google endpoints
Introduction to google endpoints
Shinto Anto
 
RIA / SPA with ASP.NET
RIA / SPA with ASP.NETRIA / SPA with ASP.NET
RIA / SPA with ASP.NET
Hrvoje Hudoletnjak
 
Vijay Oscon
Vijay OsconVijay Oscon
Vijay Oscon
vijayrvr
 
AWS Code Services
AWS Code ServicesAWS Code Services
AWS Code Services
Amazon Web Services
 
Gwt session
Gwt sessionGwt session
Gwt session
Mans Jug
 
Gwt session
Gwt sessionGwt session
Gwt session
Ahmed Akl
 
Serverless on Azure with Functions
Serverless on Azure with FunctionsServerless on Azure with Functions
Serverless on Azure with Functions
Christos 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 Comparison
Adnan 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 framework
Sunil Kumar
 
Best of Microsoft Dev Camp 2015
Best of Microsoft Dev Camp 2015Best of Microsoft Dev Camp 2015
Best of Microsoft Dev Camp 2015
Bluegrass Digital
 

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

Recently uploaded

Monitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdfMonitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdf
Tosin Akinosho
 
Main news related to the CCS TSI 2023 (2023/1695)
Main news related to the CCS TSI 2023 (2023/1695)Main news related to the CCS TSI 2023 (2023/1695)
Main news related to the CCS TSI 2023 (2023/1695)
Jakub Marek
 
Taking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdfTaking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdf
ssuserfac0301
 
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success StoryDriving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Safe Software
 
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdfHow to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
Chart Kalyan
 
UI5 Controls simplified - UI5con2024 presentation
UI5 Controls simplified - UI5con2024 presentationUI5 Controls simplified - UI5con2024 presentation
UI5 Controls simplified - UI5con2024 presentation
Wouter Lemaire
 
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy SurveyTrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc
 
AWS Cloud Cost Optimization Presentation.pptx
AWS Cloud Cost Optimization Presentation.pptxAWS Cloud Cost Optimization Presentation.pptx
AWS Cloud Cost Optimization Presentation.pptx
HarisZaheer8
 
Programming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup SlidesProgramming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup Slides
Zilliz
 
Fueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte WebinarFueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte Webinar
Zilliz
 
Digital Marketing Trends in 2024 | Guide for Staying Ahead
Digital Marketing Trends in 2024 | Guide for Staying AheadDigital Marketing Trends in 2024 | Guide for Staying Ahead
Digital Marketing Trends in 2024 | Guide for Staying Ahead
Wask
 
Building Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and MilvusBuilding Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and Milvus
Zilliz
 
Best 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERPBest 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERP
Pixlogix Infotech
 
Deep Dive: Getting Funded with Jason Jason Lemkin Founder & CEO @ SaaStr
Deep Dive: Getting Funded with Jason Jason Lemkin Founder & CEO @ SaaStrDeep Dive: Getting Funded with Jason Jason Lemkin Founder & CEO @ SaaStr
Deep Dive: Getting Funded with Jason Jason Lemkin Founder & CEO @ SaaStr
saastr
 
Artificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopmentArtificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopment
Octavian Nadolu
 
WeTestAthens: Postman's AI & Automation Techniques
WeTestAthens: Postman's AI & Automation TechniquesWeTestAthens: Postman's AI & Automation Techniques
WeTestAthens: Postman's AI & Automation Techniques
Postman
 
June Patch Tuesday
June Patch TuesdayJune Patch Tuesday
June Patch Tuesday
Ivanti
 
dbms calicut university B. sc Cs 4th sem.pdf
dbms  calicut university B. sc Cs 4th sem.pdfdbms  calicut university B. sc Cs 4th sem.pdf
dbms calicut university B. sc Cs 4th sem.pdf
Shinana2
 
Ocean lotus Threat actors project by John Sitima 2024 (1).pptx
Ocean lotus Threat actors project by John Sitima 2024 (1).pptxOcean lotus Threat actors project by John Sitima 2024 (1).pptx
Ocean lotus Threat actors project by John Sitima 2024 (1).pptx
SitimaJohn
 
Nordic Marketo Engage User Group_June 13_ 2024.pptx
Nordic Marketo Engage User Group_June 13_ 2024.pptxNordic Marketo Engage User Group_June 13_ 2024.pptx
Nordic Marketo Engage User Group_June 13_ 2024.pptx
MichaelKnudsen27
 

Recently uploaded (20)

Monitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdfMonitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdf
 
Main news related to the CCS TSI 2023 (2023/1695)
Main news related to the CCS TSI 2023 (2023/1695)Main news related to the CCS TSI 2023 (2023/1695)
Main news related to the CCS TSI 2023 (2023/1695)
 
Taking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdfTaking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdf
 
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success StoryDriving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success Story
 
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdfHow to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
 
UI5 Controls simplified - UI5con2024 presentation
UI5 Controls simplified - UI5con2024 presentationUI5 Controls simplified - UI5con2024 presentation
UI5 Controls simplified - UI5con2024 presentation
 
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy SurveyTrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy Survey
 
AWS Cloud Cost Optimization Presentation.pptx
AWS Cloud Cost Optimization Presentation.pptxAWS Cloud Cost Optimization Presentation.pptx
AWS Cloud Cost Optimization Presentation.pptx
 
Programming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup SlidesProgramming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup Slides
 
Fueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte WebinarFueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte Webinar
 
Digital Marketing Trends in 2024 | Guide for Staying Ahead
Digital Marketing Trends in 2024 | Guide for Staying AheadDigital Marketing Trends in 2024 | Guide for Staying Ahead
Digital Marketing Trends in 2024 | Guide for Staying Ahead
 
Building Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and MilvusBuilding Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and Milvus
 
Best 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERPBest 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERP
 
Deep Dive: Getting Funded with Jason Jason Lemkin Founder & CEO @ SaaStr
Deep Dive: Getting Funded with Jason Jason Lemkin Founder & CEO @ SaaStrDeep Dive: Getting Funded with Jason Jason Lemkin Founder & CEO @ SaaStr
Deep Dive: Getting Funded with Jason Jason Lemkin Founder & CEO @ SaaStr
 
Artificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopmentArtificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopment
 
WeTestAthens: Postman's AI & Automation Techniques
WeTestAthens: Postman's AI & Automation TechniquesWeTestAthens: Postman's AI & Automation Techniques
WeTestAthens: Postman's AI & Automation Techniques
 
June Patch Tuesday
June Patch TuesdayJune Patch Tuesday
June Patch Tuesday
 
dbms calicut university B. sc Cs 4th sem.pdf
dbms  calicut university B. sc Cs 4th sem.pdfdbms  calicut university B. sc Cs 4th sem.pdf
dbms calicut university B. sc Cs 4th sem.pdf
 
Ocean lotus Threat actors project by John Sitima 2024 (1).pptx
Ocean lotus Threat actors project by John Sitima 2024 (1).pptxOcean lotus Threat actors project by John Sitima 2024 (1).pptx
Ocean lotus Threat actors project by John Sitima 2024 (1).pptx
 
Nordic Marketo Engage User Group_June 13_ 2024.pptx
Nordic Marketo Engage User Group_June 13_ 2024.pptxNordic Marketo Engage User Group_June 13_ 2024.pptx
Nordic Marketo Engage User Group_June 13_ 2024.pptx
 

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

Editor's Notes

  1. Ask for usage?