SlideShare ist ein Scribd-Unternehmen logo
1 von 42
Downloaden Sie, um offline zu lesen
Simple	REST-APIs	with	
Dropwizard and	Swagger
Bernd	Schönbach
LeanIX GmbH
@boernd_s
Motivation
2REST-APIs	with Dropwizard &	Swagger – VoxxedDays Berlin	2016	– Bernd	Schönbach	– LeanIX GmbH
- Quickly	create	REST-APIs
- Make	them	testable
- Make	them	deployable	with	a	click
- Or	even	better	automatically
- Provide	Documentation	without	MS	Office
- Provide	SDK	with	no	extra	action	needed
Overview
3REST-APIs	with Dropwizard &	Swagger – VoxxedDays Berlin	2016	– Bernd	Schönbach	– LeanIX GmbH
Introduction
• About	me
• About	LeanIX
Dropwizard
• Set	Up	/	Basic	Features
• Demo
• Advanced	Features
Swagger	+	Swagger	UI
• Set	Up	/	Basic	Features
• Demo
• Advanced	Features
Introduction
About me
5REST-APIs	with Dropwizard &	Swagger – VoxxedDays Berlin	2016	– Bernd	Schönbach	– LeanIX GmbH
EnvironmentBernd Schönbach
• Est.:	1982
• First	Language:	PHP	(2001)
• Second	Language:	Java	(2010)
• Java-Dev. @leanIX:	2015	-
LeanIX	was	born,	since pragmatic solutions for
IT	Architecture Management	did not	exist
6REST-APIs	with Dropwizard &	Swagger – VoxxedDays Berlin	2016	– Bernd	Schönbach	– LeanIX GmbH
Jörg	G.	Beyer André	Christ
Management-Team	&	FounderLeanIX GmbH
• Headquarter:	Bonn
• Founded:	01/2012
• Launch:	08/2012
• 4	years	Management	
Consulting	@	DHL
• 8	years	Freelancer	
Software	Design	&	
Architecture
• Speaker	&	Author	for	
Software	Architecture
• 10	years	IT	Leadership	@	
DHL,	e.g.	global	CIO
• 4	years	MD	for	newly	
established	IT	Management	
Consulting	
• 10	years	Consulting:	
Andersen	&	self-employed
LeanIX	helps	companies	to	manage	and	
optimize	their	IT	Architectures
7REST-APIs	with Dropwizard &	Swagger – VoxxedDays Berlin	2016	– Bernd	Schönbach	– LeanIX GmbH
Current IT	Architecture Create	Transparency Optimize IT	Architecture
• Missing	information	(e.g.	
interfaces,	technologies)
• Hard	to	introduce	new	
products	&	sales	channels
• High	costs	and	risks
• Import	existing	data	into	
LeanIX	(via	Excel	or	API)
• Invite	experts	to	share	
their	knowledge
• Use	best-practice	reports	
to	identify	issues
• Define	target	architecture	
and	roadmaps
Learn more: https://www.leanix.net/en/product/index
LeanIX	is	a	web-based	platform
to	capture	and	share	knowledge	about	IT
8REST-APIs	with Dropwizard &	Swagger – VoxxedDays Berlin	2016	– Bernd	Schönbach	– LeanIX GmbH
Fact	Sheets	&	Tagging
Context-based	Search
API,	Import	&	Export
Comments	&	Threads
IT	Inventory Collaboration	Platform Interactive	Reporting
Activity	Stream	&	
Notifications
Subscriptions
Print	&	Export	(PDF)
Best	Practice	Reports
Interactive	Adaption
Learn more: https://www.leanix.net/en/product/index
Market	leading companies already use LeanIX
9
Media
Insurance
Industry
e-Commerce
Telecoms
Chemical
Advisory
Government
Manufacturing
Logistics
Education
Health
Energy
See more: https://www.leanix.net/en/customers/index
Dropwizard
Dropwizard
11REST-APIs	with Dropwizard &	Swagger – VoxxedDays Berlin	2016	– Bernd	Schönbach	– LeanIX GmbH
Live	Demo
Overview
What	is	it?
The	Basics
Advanced Features
• Java	Framework	for RESTful Web	Services
• Quick	Startup	(few seconds)
• Completely configurable
• Current Version:	0.9.2	
(we will	be using 0.9.1)
Dropwizard
12REST-APIs	with Dropwizard &	Swagger – VoxxedDays Berlin	2016	– Bernd	Schönbach	– LeanIX GmbH
Live	Demo
Overview
What	is	it?
The	Basics
Advanced Features
• Framework	Contents:
• Jetty for HTTP
• Jersey	for REST
• Jackson	for JSON	transformation
• Hibernate for DB	Access
• Other	usefull inclusions
• Metrics
• Liquibase
• Slf4j	and Logback
• and much more...
Dropwizard
13REST-APIs	with Dropwizard &	Swagger – VoxxedDays Berlin	2016	– Bernd	Schönbach	– LeanIX GmbH
First	Steps:	
What	is	it?
The	Basics
Advanced Features
• Create	Maven	Project
• Add	dependency	to	dropwizard
• Configure	Maven	Shade	Plugin
• Add	configuration	file	(optional)
• Start	coding
Dropwizard
14REST-APIs	with Dropwizard &	Swagger – VoxxedDays Berlin	2016	– Bernd	Schönbach	– LeanIX GmbH
Add	dependency to pom.xml
Standard	way (dropwizard only)
What	is	it?
The	Basics
Advanced Features
<properties>
<dropwizard.version>0.9.1</dropwizard.version>
</properties>
Step	1:
Step	2:
<dependencies>
<dependency>
<groupId>io.dropwizard</groupId>
<artifactId>dropwizard-core</artifactId>
<version>${dropwizard.version}</version>
</dependency>
</dependencies>
Dropwizard
15REST-APIs	with Dropwizard &	Swagger – VoxxedDays Berlin	2016	– Bernd	Schönbach	– LeanIX GmbH
Add	dependency to pom.xml
Our way (Swagger &	Dropwizard together)
What	is	it?
The	Basics
Advanced Features
<properties>
<dropwizard.version>0.9.1-1</dropwizard.version>
</properties>
Step	1:
Step	2:
<dependencies>
<dependency>
<groupId>com.smoketurner</groupId>
<artifactId>dropwizard-swagger</artifactId>
<version>${dropwizard.version}	</version>
</dependency>
</dependencies>
Dropwizard
16REST-APIs	with Dropwizard &	Swagger – VoxxedDays Berlin	2016	– Bernd	Schönbach	– LeanIX GmbH
Configure Maven Shade Plugin
What	is	it?
The	Basics
Advanced Features
<plugin>
<artifactId>maven-shade-plugin</artifactId>								
<version>2.4.1</version>								
<executions>										
<execution>												
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration combine.children="append">														
<createDependencyReducedPom>
true
</createDependencyReducedPom>														
<outputFile>target/voxxed-test.jar</outputFile>
[...]
</configuration>
</execution>								
</executions>						
</plugin>
Let’s	code!
Dropwizard
18REST-APIs	with Dropwizard &	Swagger – VoxxedDays Berlin	2016	– Bernd	Schönbach	– LeanIX GmbH
Configure your Application
What	is	it?
The	Basics
Advanced Features
config.yml
server:	
applicationConnectors:
type: http
port: 1337
adminConnectors:
type: http
port: $env:ADMIN_PORT:1338
Logging:
level: INFO
FooBar: Value
Dropwizard
19REST-APIs	with Dropwizard &	Swagger – VoxxedDays Berlin	2016	– Bernd	Schönbach	– LeanIX GmbH
Resource Methods and Paths
What	is	it?
The	Basics
Advanced Features
@Path(“persons”)
public class PersonResource {
@GET
public String getPersons () {[…]}
@PUT	
public String	updatePerson()	{[…]}
@POST	
public String	createPerson()	{[…]}
@DELETE	
public String	deletePerson()	{[…]}
URL:	localhost:1337/persons
@GET	
@Path("/address"}	
public String	getPersonAddress()	{[…]}
URL:	localhost:1337/persons/address
Dropwizard
20REST-APIs	with Dropwizard &	Swagger – VoxxedDays Berlin	2016	– Bernd	Schönbach	– LeanIX GmbH
Query	and Path	Params
What	is	it?
The	Basics
Advanced Features
Task	1:	Search	an	Entity.
URL:	http://localhost:1337/persons?name=adam
Task	2:	Retrieve	an	Entity:
URL:	http://localhost:1337/persons/1234/
Query	Parameters
public class PersonResource {
@GET	
public String getPerson(
@QueryParam(“name”) String name
) {[…]}
Path	Parameters
public class PersonResource {
@GET
@Path(“/{id}”)
public String getPersonById(
@PathParam(“id”) String id
) {[…]}
Dropwizard
21REST-APIs	with Dropwizard &	Swagger – VoxxedDays Berlin	2016	– Bernd	Schönbach	– LeanIX GmbH
Response	Types
What	is	it?
The	Basics
Advanced Features
Return	and	retrieve	JSON
@Produces(MediaType.APPLICATION_JSON)	
@Consumes(MediaType.APPLICATION_JSON)	
public class PersonResource {
@GET	
public String getPerson (
@QueryParam(“name”) String name
) {[…]}
@Produces(MediaType.APPLICATION_JSON)	
@Consumes(MediaType.APPLICATION_JSON)	
public class PersonResource {
@GET	
public String getPerson (
@QueryParam(“name”) String name
) {[…]}
@GET	
@Path(“xml”)
@Produces(MediaType.APPLICATION_XML)
public String getPersonXml (){
[…]
}
Dropwizard
22REST-APIs	with Dropwizard &	Swagger – VoxxedDays Berlin	2016	– Bernd	Schönbach	– LeanIX GmbH
What	is	it?
The	Basics
Advanced Features
Advanced	Features
- HATEOAS
- Validators	and	Defaults	for	Query	Parameters
- Authentication	Handling
Dropwizard
23REST-APIs	with Dropwizard &	Swagger – VoxxedDays Berlin	2016	– Bernd	Schönbach	– LeanIX GmbH
Pimping your Response	(HATEOAS)
- Add	Meta	Information	to	Response	Data
- Provide	Links	to	allow	automated	traversal	(by	machines)
{
data:	[{…},…,{…}]
size:	10
total:	150
links:	{
next:		“/persons/page=2&limit=10”,
current:	“/persons/page=1&limit=10”,
previous:	null
}
}
What	is	it?
The	Basics
Advanced Features
Dropwizard
24REST-APIs	with Dropwizard &	Swagger – VoxxedDays Berlin	2016	– Bernd	Schönbach	– LeanIX GmbH
Pimping your Response	(HATEOAS)
Response	Objects
What	is	it?
The	Basics
Advanced Features
public class BasicResponse {
protected ResponseStatus status = ResponseStatus.OK;
protected String type;
protected String message;
protected Long total;
[…]
}
public class PersonResponse extends BasicResponse {
protected Person	data;
protected Links	links;
public class Links	{
protected String next;
protected String previous;
protected String current;
}
}
Dropwizard
25REST-APIs	with Dropwizard &	Swagger – VoxxedDays Berlin	2016	– Bernd	Schönbach	– LeanIX GmbH
Pimping your Response	(HATEOAS)
Option	B:	Jersey	Links
What	is	it?
The	Basics
Advanced Features
public void run(AppConfig conf,	Environment	env)	throws Ex	{
environment.jersey().getResourceConfig()
.packages(getClass().getPackage().getName())
.register(DeclarativeLinkingFeature.class);
}
App.java
- Add	dependency	to	jersey-server-linking
- Register	in	run	function	of	App.java
- Add	@Link	or	@Ref	Annotations
For	further	Information	see:
https://jersey.java.net/documentation/1.19/linking.html
Dropwizard
26REST-APIs	with Dropwizard &	Swagger – VoxxedDays Berlin	2016	– Bernd	Schönbach	– LeanIX GmbH
Validators and Defaults	for
Query	Parameters
What	is	it?
The	Basics
Advanced Features
public class PersonResource {
@GET
public String getPerson (
@QueryParam(“name”) String name
) {[…]}
public class PersonResource {
@GET	
public String getPerson (
@QueryParam(“name”) @NotEmpty String name
) {[…]}
Validating:
Supplied	by	Hibernate	Validator
@NotNull
@Min(Integer);	@Max(Integer)
@Size(min	=	Integer,	max	=	Integer)
@Future,	@Past
@Pattern(regex=	String)
@Valid
Dropwizard
27REST-APIs	with Dropwizard &	Swagger – VoxxedDays Berlin	2016	– Bernd	Schönbach	– LeanIX GmbH
Authentication	Handling
What	is	it?
The	Basics
Advanced Features
Step	1:	Create	Authentication	Provider:
public class ExampleAuthenticator implements
Authenticator<BasicCredentials,	User>	{
@Override
public Optional<User> authenticate(
BasicCredentials credentials
) throws AuthenticationException
{
if ("secret".equals(credentials.getPassword())) {
return Optional.of(new User(credentials.getUsername()));
}
return Optional.absent();
}
}
Dropwizard
28REST-APIs	with Dropwizard &	Swagger – VoxxedDays Berlin	2016	– Bernd	Schönbach	– LeanIX GmbH
Authentication	Handling
What	is	it?
The	Basics
Advanced Features
Step	2:	Register	Authentication	Provider:
public void run(AppConfig conf,	Environment	env)	throws Ex	{	
environment.jersey().register(
new AuthDynamicFeature(
new BasicCredentialAuthFilter.Builder<User>()
.setAuthenticator(new ExampleAuthenticator())
.setRealm("SUPER	SECRET	STUFF") .buildAuthFilter()
)
);
environment.jersey().register(
RolesAllowedDynamicFeature.class
);
environment.jersey().register(
new AuthValueFactoryProvider.Binder<>(User.class)
);
}
Dropwizard
29REST-APIs	with Dropwizard &	Swagger – VoxxedDays Berlin	2016	– Bernd	Schönbach	– LeanIX GmbH
Authentication	Handling
What	is	it?
The	Basics
Advanced Features
Step	3:	Use	Auth Parameter:
public class PersonResource {
@GET	
public String getPerson (
@QueryParam(“name”) @NotEmpty String name,
@Auth User	auth )
{
[…]
}
}
Swagger
+
Swagger	UI
Swagger
31REST-APIs	with Dropwizard &	Swagger – VoxxedDays Berlin	2016	– Bernd	Schönbach	– LeanIX GmbH
Swagger +	Swagger UI
What	is	it?
The	Basics
Advanced Features
- Simple	documentation	for	REST	APIs
- Allows	automatic	SDK	Generation
- Nice	and	interactive	User	Interface
32
Swagger Workflow
33REST-APIs	with Dropwizard &	Swagger – VoxxedDays Berlin	2016	– Bernd	Schönbach	– LeanIX GmbH
JSON
Specification
HTML	API	UI
SDK	Generation
Code
Annotation
Let’s	code!
Swagger
35REST-APIs	with Dropwizard &	Swagger – VoxxedDays Berlin	2016	– Bernd	Schönbach	– LeanIX GmbH
Basic	Annotations
What	is	it?
The	Basics
Advanced Features
@Api(“Description”)
@ApiResponse
@ApiResponses
@ApiOperation(
value	=	String,
notes	=	String,
response	=	Class,	
responseContainer =	String
)
@ApiParam()
@DefaultValue(mixed)
Swagger
36REST-APIs	with Dropwizard &	Swagger – VoxxedDays Berlin	2016	– Bernd	Schönbach	– LeanIX GmbH
Basic	Annotations
What	is	it?
The	Basics
Advanced Features
@ApiParam(
name	=	String,
value	=	String,
defaultValue =	String,
required	=	Boolean,
allowableValues =	String,
example=	String,
hidden	=	Boolean
)
Swagger
37REST-APIs	with Dropwizard &	Swagger – VoxxedDays Berlin	2016	– Bernd	Schönbach	– LeanIX GmbH
Further	Annotations
What	is	it?
The	Basics
Advanced Features
@ApiModel(
value=	String,	description=	String
)	
@ApiModelProperty(
value	=	String,	allowableValues=	String
)
@Contact
@License
Swagger
38REST-APIs	with Dropwizard &	Swagger – VoxxedDays Berlin	2016	– Bernd	Schönbach	– LeanIX GmbH
Live	Demo
Advanced Features
SDK	Generation
What	is	it?
The	Basics
Advanced Features
Example for PHP	and Java:
https://github.com/leanix/swagger-demo-codegen
Configuration for that:
https://goo.gl/plH6pB
Thank you!
Learn More about LeanIX
Share on LinkedIn
http://bit.ly/LeanIXDemoS
Request free demo
http://bit.ly/LeanIXDemoS
Questions?
Sources
REST-APIs	with Dropwizard &	Swagger – VoxxedDays Berlin	2016	– Bernd	Schönbach	– LeanIX GmbH
• Dropwizard:	 http://www.dropwizard.io/
• Swagger:	 http://swagger.io/
• Swagger-UI:	 http://swagger.io/swagger-ui/
• Hibernate	Validator:	 http://hibernate.org/validator/
• Dropwizard Swagger	Package:	 https://github.com/smoketurner/dropwizard-swagger
Slides	will	be	available	at
REST-APIs	with Dropwizard &	Swagger – VoxxedDays Berlin	2016	– Bernd	Schönbach	– LeanIX GmbH
LeanIX	Website:	https://www.leanix.net/
LeanIX	Blog:	http://blog.leanix.net/
Slideshare:	http://slideshare.net/leanIX_net/
Share on LinkedIn

Weitere ähnliche Inhalte

Was ist angesagt?

Unit 7
Unit 7Unit 7
Unit 7
siddr
 
Zero-Copy Event-Driven Servers with Netty
Zero-Copy Event-Driven Servers with NettyZero-Copy Event-Driven Servers with Netty
Zero-Copy Event-Driven Servers with Netty
Daniel Bimschas
 
WebLogic Administration und Deployment mit WLST
WebLogic Administration und Deployment mit WLSTWebLogic Administration und Deployment mit WLST
WebLogic Administration und Deployment mit WLST
enpit GmbH & Co. KG
 
Chapter04 Implementing And Managing Group And Computer Accounts
Chapter04      Implementing And  Managing  Group And  Computer  AccountsChapter04      Implementing And  Managing  Group And  Computer  Accounts
Chapter04 Implementing And Managing Group And Computer Accounts
Raja Waseem Akhtar
 

Was ist angesagt? (20)

Angular 2.0 Pipes
Angular 2.0 PipesAngular 2.0 Pipes
Angular 2.0 Pipes
 
Tugas PPT Tutorial Power Point 2010
Tugas PPT Tutorial Power Point 2010Tugas PPT Tutorial Power Point 2010
Tugas PPT Tutorial Power Point 2010
 
Modul Ajar Basis Data
Modul Ajar Basis DataModul Ajar Basis Data
Modul Ajar Basis Data
 
RDF 개념 및 구문 소개
RDF 개념 및 구문 소개RDF 개념 및 구문 소개
RDF 개념 및 구문 소개
 
Introduction to Grails Framework
Introduction to Grails FrameworkIntroduction to Grails Framework
Introduction to Grails Framework
 
ODI User and Security
ODI User and Security ODI User and Security
ODI User and Security
 
Python and MongoDB
Python and MongoDBPython and MongoDB
Python and MongoDB
 
Rest api with node js and express
Rest api with node js and expressRest api with node js and express
Rest api with node js and express
 
MyBatis, une alternative à JPA.
MyBatis, une alternative à JPA.MyBatis, une alternative à JPA.
MyBatis, une alternative à JPA.
 
Jcl faqs
Jcl faqsJcl faqs
Jcl faqs
 
Unit 7
Unit 7Unit 7
Unit 7
 
Zero-Copy Event-Driven Servers with Netty
Zero-Copy Event-Driven Servers with NettyZero-Copy Event-Driven Servers with Netty
Zero-Copy Event-Driven Servers with Netty
 
Apache Spark on K8S and HDFS Security with Ilan Flonenko
Apache Spark on K8S and HDFS Security with Ilan FlonenkoApache Spark on K8S and HDFS Security with Ilan Flonenko
Apache Spark on K8S and HDFS Security with Ilan Flonenko
 
Building ext js apps with ES2015 using sencha visual studio code plugin
Building ext js apps with ES2015 using sencha visual studio code pluginBuilding ext js apps with ES2015 using sencha visual studio code plugin
Building ext js apps with ES2015 using sencha visual studio code plugin
 
AI Accelerators for Cloud Datacenters
AI Accelerators for Cloud DatacentersAI Accelerators for Cloud Datacenters
AI Accelerators for Cloud Datacenters
 
WebLogic Administration und Deployment mit WLST
WebLogic Administration und Deployment mit WLSTWebLogic Administration und Deployment mit WLST
WebLogic Administration und Deployment mit WLST
 
Django class based views for beginners
Django class based views for beginnersDjango class based views for beginners
Django class based views for beginners
 
Kamailio - Large Unified Communication Platforms
Kamailio - Large Unified Communication PlatformsKamailio - Large Unified Communication Platforms
Kamailio - Large Unified Communication Platforms
 
Fun with Lambdas: C++14 Style (part 1)
Fun with Lambdas: C++14 Style (part 1)Fun with Lambdas: C++14 Style (part 1)
Fun with Lambdas: C++14 Style (part 1)
 
Chapter04 Implementing And Managing Group And Computer Accounts
Chapter04      Implementing And  Managing  Group And  Computer  AccountsChapter04      Implementing And  Managing  Group And  Computer  Accounts
Chapter04 Implementing And Managing Group And Computer Accounts
 

Andere mochten auch

Andere mochten auch (20)

Simple REST with Dropwizard
Simple REST with DropwizardSimple REST with Dropwizard
Simple REST with Dropwizard
 
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
 
Dropwizard Introduction
Dropwizard IntroductionDropwizard Introduction
Dropwizard Introduction
 
Dropwizard
DropwizardDropwizard
Dropwizard
 
Tech Talk: DevOps at LeanIX @ Startup Camp Berlin
Tech Talk: DevOps at LeanIX @ Startup Camp BerlinTech Talk: DevOps at LeanIX @ Startup Camp Berlin
Tech Talk: DevOps at LeanIX @ Startup Camp Berlin
 
Operations-Driven Web Services at Rent the Runway
Operations-Driven Web Services at Rent the RunwayOperations-Driven Web Services at Rent the Runway
Operations-Driven Web Services at Rent the Runway
 
LeanIX Enterprise Architecture Management - Release Notes 3.4
LeanIX Enterprise Architecture Management - Release Notes 3.4 LeanIX Enterprise Architecture Management - Release Notes 3.4
LeanIX Enterprise Architecture Management - Release Notes 3.4
 
LeanIX Enterprise Architecture Management @ 3rd EA Connect Day 2016
LeanIX Enterprise Architecture Management @ 3rd EA Connect Day 2016LeanIX Enterprise Architecture Management @ 3rd EA Connect Day 2016
LeanIX Enterprise Architecture Management @ 3rd EA Connect Day 2016
 
Fault tolerant microservices - LJC Skills Matter 4thNov2014
Fault tolerant microservices - LJC Skills Matter 4thNov2014Fault tolerant microservices - LJC Skills Matter 4thNov2014
Fault tolerant microservices - LJC Skills Matter 4thNov2014
 
Trends in Enterprise Architecture Management (EAM) Tools
Trends in Enterprise Architecture Management (EAM) ToolsTrends in Enterprise Architecture Management (EAM) Tools
Trends in Enterprise Architecture Management (EAM) Tools
 
Soa with consul
Soa with consulSoa with consul
Soa with consul
 
JEE on DC/OS
JEE on DC/OSJEE on DC/OS
JEE on DC/OS
 
GraphQL in LeanIX Enterprise Architecture Management @ Bonnagile Meetup
GraphQL in LeanIX Enterprise Architecture Management @ Bonnagile MeetupGraphQL in LeanIX Enterprise Architecture Management @ Bonnagile Meetup
GraphQL in LeanIX Enterprise Architecture Management @ Bonnagile Meetup
 
Production Ready Web Services with Dropwizard
Production Ready Web Services with DropwizardProduction Ready Web Services with Dropwizard
Production Ready Web Services with Dropwizard
 
CodeTalks Vortrag: Automatisierung mit Ansible & Jenkins @ LeanIX Enterprise ...
CodeTalks Vortrag: Automatisierung mit Ansible & Jenkins @ LeanIX Enterprise ...CodeTalks Vortrag: Automatisierung mit Ansible & Jenkins @ LeanIX Enterprise ...
CodeTalks Vortrag: Automatisierung mit Ansible & Jenkins @ LeanIX Enterprise ...
 
Dropwizard Spring - the perfect Java REST server stack
Dropwizard Spring - the perfect Java REST server stackDropwizard Spring - the perfect Java REST server stack
Dropwizard Spring - the perfect Java REST server stack
 
The Next Big Thing
The Next Big ThingThe Next Big Thing
The Next Big Thing
 
LeanIX Swagger REST API @ Open Source Konferenz FrosCon, Sankt Augustin
LeanIX Swagger REST API @ Open Source Konferenz FrosCon, Sankt AugustinLeanIX Swagger REST API @ Open Source Konferenz FrosCon, Sankt Augustin
LeanIX Swagger REST API @ Open Source Konferenz FrosCon, Sankt Augustin
 
Dropwizard and Groovy
Dropwizard and GroovyDropwizard and Groovy
Dropwizard and Groovy
 
Alle reden über Microservices - Wie haben wir es bei LeanIX gemacht @ EA Conn...
Alle reden über Microservices - Wie haben wir es bei LeanIX gemacht @ EA Conn...Alle reden über Microservices - Wie haben wir es bei LeanIX gemacht @ EA Conn...
Alle reden über Microservices - Wie haben wir es bei LeanIX gemacht @ EA Conn...
 

Ähnlich wie Simple REST-APIs with Dropwizard and Swagger

ArcReady - Architecting Modern Distributed Applications
ArcReady -  Architecting Modern Distributed ApplicationsArcReady -  Architecting Modern Distributed Applications
ArcReady - Architecting Modern Distributed Applications
Microsoft ArcReady
 
Lorenz Lo Sauer portfolio 2013
Lorenz Lo Sauer portfolio 2013Lorenz Lo Sauer portfolio 2013
Lorenz Lo Sauer portfolio 2013
Lorenz Lo Sauer
 

Ähnlich wie Simple REST-APIs with Dropwizard and Swagger (20)

Serverless survival kit
Serverless survival kitServerless survival kit
Serverless survival kit
 
Openshift Container Platform: First ItalyMeetup
Openshift Container Platform: First ItalyMeetupOpenshift Container Platform: First ItalyMeetup
Openshift Container Platform: First ItalyMeetup
 
Introduction to Microsoft Flow : Power to the People (Serge Luca, Isabelle Va...
Introduction to Microsoft Flow : Power to the People (Serge Luca, Isabelle Va...Introduction to Microsoft Flow : Power to the People (Serge Luca, Isabelle Va...
Introduction to Microsoft Flow : Power to the People (Serge Luca, Isabelle Va...
 
Microsoft Flow - SharePoint Saturday Paris 2017
Microsoft Flow - SharePoint Saturday Paris 2017Microsoft Flow - SharePoint Saturday Paris 2017
Microsoft Flow - SharePoint Saturday Paris 2017
 
B5 - Introduction à Microsoft Flow - Isabelle Van Campenhoudt, Sabrine chouk,...
B5 - Introduction à Microsoft Flow - Isabelle Van Campenhoudt, Sabrine chouk,...B5 - Introduction à Microsoft Flow - Isabelle Van Campenhoudt, Sabrine chouk,...
B5 - Introduction à Microsoft Flow - Isabelle Van Campenhoudt, Sabrine chouk,...
 
Hybrid Integration with SAP
Hybrid Integration with SAPHybrid Integration with SAP
Hybrid Integration with SAP
 
Best practices: embedding interactive reports & visualizations in your app
Best practices: embedding interactive reports & visualizations in your appBest practices: embedding interactive reports & visualizations in your app
Best practices: embedding interactive reports & visualizations in your app
 
Hybrid integrationwithsap (Glenn Colpaert @ Integration Monday)
Hybrid integrationwithsap (Glenn Colpaert @ Integration Monday)Hybrid integrationwithsap (Glenn Colpaert @ Integration Monday)
Hybrid integrationwithsap (Glenn Colpaert @ Integration Monday)
 
Ibm_interconnect_restapi_workshop
Ibm_interconnect_restapi_workshopIbm_interconnect_restapi_workshop
Ibm_interconnect_restapi_workshop
 
Summit Australia 2019 - PowerApp Portals - Andrew Ly & Lachlan Wright
Summit Australia 2019 - PowerApp Portals - Andrew Ly & Lachlan WrightSummit Australia 2019 - PowerApp Portals - Andrew Ly & Lachlan Wright
Summit Australia 2019 - PowerApp Portals - Andrew Ly & Lachlan Wright
 
Introduction to Microsoft Flow - Introduction & advanced scenarios
Introduction to Microsoft Flow - Introduction & advanced scenariosIntroduction to Microsoft Flow - Introduction & advanced scenarios
Introduction to Microsoft Flow - Introduction & advanced scenarios
 
Embarcadero RAD server Launch Webinar
Embarcadero RAD server Launch WebinarEmbarcadero RAD server Launch Webinar
Embarcadero RAD server Launch Webinar
 
Connect(); 2016 한시간 총정리
Connect(); 2016 한시간 총정리Connect(); 2016 한시간 총정리
Connect(); 2016 한시간 총정리
 
Serverless with Spring Cloud Function, Knative and riff #SpringOneTour #s1t
Serverless with Spring Cloud Function, Knative and riff #SpringOneTour #s1tServerless with Spring Cloud Function, Knative and riff #SpringOneTour #s1t
Serverless with Spring Cloud Function, Knative and riff #SpringOneTour #s1t
 
ArcReady - Architecting Modern Distributed Applications
ArcReady -  Architecting Modern Distributed ApplicationsArcReady -  Architecting Modern Distributed Applications
ArcReady - Architecting Modern Distributed Applications
 
Generating Unified APIs with Protocol Buffers and gRPC
Generating Unified APIs with Protocol Buffers and gRPCGenerating Unified APIs with Protocol Buffers and gRPC
Generating Unified APIs with Protocol Buffers and gRPC
 
DevNet Express - Spark & Tropo API - Lisbon May 2016
DevNet Express - Spark & Tropo API - Lisbon May 2016DevNet Express - Spark & Tropo API - Lisbon May 2016
DevNet Express - Spark & Tropo API - Lisbon May 2016
 
Microsoft Graph: Connect to essential data every app needs
Microsoft Graph: Connect to essential data every app needsMicrosoft Graph: Connect to essential data every app needs
Microsoft Graph: Connect to essential data every app needs
 
Microsoft Graph: Connect to essential data every app needs
Microsoft Graph: Connect to essential data every app needsMicrosoft Graph: Connect to essential data every app needs
Microsoft Graph: Connect to essential data every app needs
 
Lorenz Lo Sauer portfolio 2013
Lorenz Lo Sauer portfolio 2013Lorenz Lo Sauer portfolio 2013
Lorenz Lo Sauer portfolio 2013
 

Mehr von LeanIX GmbH

Mehr von LeanIX GmbH (20)

LeanIX Virtual Workspaces
LeanIX Virtual WorkspacesLeanIX Virtual Workspaces
LeanIX Virtual Workspaces
 
How to reduce complexity by segregating your data with Virtual Workspaces
How to reduce complexity by segregating your data with Virtual WorkspacesHow to reduce complexity by segregating your data with Virtual Workspaces
How to reduce complexity by segregating your data with Virtual Workspaces
 
Gartner EA: The Rise of Data-driven Architectures
Gartner EA: The Rise of Data-driven ArchitecturesGartner EA: The Rise of Data-driven Architectures
Gartner EA: The Rise of Data-driven Architectures
 
Application Harmonisation using Design Principles in LeanIX
Application Harmonisation using Design Principles in LeanIXApplication Harmonisation using Design Principles in LeanIX
Application Harmonisation using Design Principles in LeanIX
 
Effective EAM: whet your appetite & deliver solutions
Effective EAM: whet your appetite & deliver solutionsEffective EAM: whet your appetite & deliver solutions
Effective EAM: whet your appetite & deliver solutions
 
Lean EAM with the Microservices Add-on and the Signavio Integration
Lean EAM with the Microservices Add-on and the Signavio IntegrationLean EAM with the Microservices Add-on and the Signavio Integration
Lean EAM with the Microservices Add-on and the Signavio Integration
 
Next Level Enterprise Architecture
Next Level Enterprise ArchitectureNext Level Enterprise Architecture
Next Level Enterprise Architecture
 
Integration Architecture with the Data Flow
Integration Architecture with the Data FlowIntegration Architecture with the Data Flow
Integration Architecture with the Data Flow
 
LeanIX-ServiceNow Integration
LeanIX-ServiceNow IntegrationLeanIX-ServiceNow Integration
LeanIX-ServiceNow Integration
 
Application Rationalization with LeanIX
Application Rationalization with LeanIXApplication Rationalization with LeanIX
Application Rationalization with LeanIX
 
Custom Reports & Integrations with GraphQL
Custom Reports & Integrations with GraphQLCustom Reports & Integrations with GraphQL
Custom Reports & Integrations with GraphQL
 
LeanIX Inventory: Import & Export
LeanIX Inventory: Import & ExportLeanIX Inventory: Import & Export
LeanIX Inventory: Import & Export
 
Survey Add-on Showcase: Cloud Transformation
Survey Add-on Showcase: Cloud TransformationSurvey Add-on Showcase: Cloud Transformation
Survey Add-on Showcase: Cloud Transformation
 
The LeanIX Microservices Integration
The LeanIX Microservices IntegrationThe LeanIX Microservices Integration
The LeanIX Microservices Integration
 
Ensure GDPR Compliance with LeanIX
Ensure GDPR Compliance with LeanIXEnsure GDPR Compliance with LeanIX
Ensure GDPR Compliance with LeanIX
 
LeanIX-Signavio Integration
LeanIX-Signavio IntegrationLeanIX-Signavio Integration
LeanIX-Signavio Integration
 
How to set up a Lean Standards Governance
How to set up a Lean Standards GovernanceHow to set up a Lean Standards Governance
How to set up a Lean Standards Governance
 
Innovative API-Based LeanIX Enhancements
Innovative API-Based LeanIX EnhancementsInnovative API-Based LeanIX Enhancements
Innovative API-Based LeanIX Enhancements
 
Moving EA - from where we are to where we should be
Moving EA - from where we are to where we should beMoving EA - from where we are to where we should be
Moving EA - from where we are to where we should be
 
Is next generation EAM more than just agile IT planning?
Is next generation EAM more than just agile IT planning?Is next generation EAM more than just agile IT planning?
Is next generation EAM more than just agile IT planning?
 

Kürzlich hochgeladen

Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo DiehlFuture Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
Peter Udo Diehl
 

Kürzlich hochgeladen (20)

Strategic AI Integration in Engineering Teams
Strategic AI Integration in Engineering TeamsStrategic AI Integration in Engineering Teams
Strategic AI Integration in Engineering Teams
 
Salesforce Adoption – Metrics, Methods, and Motivation, Antone Kom
Salesforce Adoption – Metrics, Methods, and Motivation, Antone KomSalesforce Adoption – Metrics, Methods, and Motivation, Antone Kom
Salesforce Adoption – Metrics, Methods, and Motivation, Antone Kom
 
Oauth 2.0 Introduction and Flows with MuleSoft
Oauth 2.0 Introduction and Flows with MuleSoftOauth 2.0 Introduction and Flows with MuleSoft
Oauth 2.0 Introduction and Flows with MuleSoft
 
TEST BANK For, Information Technology Project Management 9th Edition Kathy Sc...
TEST BANK For, Information Technology Project Management 9th Edition Kathy Sc...TEST BANK For, Information Technology Project Management 9th Edition Kathy Sc...
TEST BANK For, Information Technology Project Management 9th Edition Kathy Sc...
 
Powerful Start- the Key to Project Success, Barbara Laskowska
Powerful Start- the Key to Project Success, Barbara LaskowskaPowerful Start- the Key to Project Success, Barbara Laskowska
Powerful Start- the Key to Project Success, Barbara Laskowska
 
Intro in Product Management - Коротко про професію продакт менеджера
Intro in Product Management - Коротко про професію продакт менеджераIntro in Product Management - Коротко про професію продакт менеджера
Intro in Product Management - Коротко про професію продакт менеджера
 
ASRock Industrial FDO Solutions in Action for Industrial Edge AI _ Kenny at A...
ASRock Industrial FDO Solutions in Action for Industrial Edge AI _ Kenny at A...ASRock Industrial FDO Solutions in Action for Industrial Edge AI _ Kenny at A...
ASRock Industrial FDO Solutions in Action for Industrial Edge AI _ Kenny at A...
 
Secure Zero Touch enabled Edge compute with Dell NativeEdge via FDO _ Brad at...
Secure Zero Touch enabled Edge compute with Dell NativeEdge via FDO _ Brad at...Secure Zero Touch enabled Edge compute with Dell NativeEdge via FDO _ Brad at...
Secure Zero Touch enabled Edge compute with Dell NativeEdge via FDO _ Brad at...
 
Simplified FDO Manufacturing Flow with TPMs _ Liam at Infineon.pdf
Simplified FDO Manufacturing Flow with TPMs _ Liam at Infineon.pdfSimplified FDO Manufacturing Flow with TPMs _ Liam at Infineon.pdf
Simplified FDO Manufacturing Flow with TPMs _ Liam at Infineon.pdf
 
Integrating Telephony Systems with Salesforce: Insights and Considerations, B...
Integrating Telephony Systems with Salesforce: Insights and Considerations, B...Integrating Telephony Systems with Salesforce: Insights and Considerations, B...
Integrating Telephony Systems with Salesforce: Insights and Considerations, B...
 
WSO2CONMay2024OpenSourceConferenceDebrief.pptx
WSO2CONMay2024OpenSourceConferenceDebrief.pptxWSO2CONMay2024OpenSourceConferenceDebrief.pptx
WSO2CONMay2024OpenSourceConferenceDebrief.pptx
 
Free and Effective: Making Flows Publicly Accessible, Yumi Ibrahimzade
Free and Effective: Making Flows Publicly Accessible, Yumi IbrahimzadeFree and Effective: Making Flows Publicly Accessible, Yumi Ibrahimzade
Free and Effective: Making Flows Publicly Accessible, Yumi Ibrahimzade
 
Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo DiehlFuture Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
 
Speed Wins: From Kafka to APIs in Minutes
Speed Wins: From Kafka to APIs in MinutesSpeed Wins: From Kafka to APIs in Minutes
Speed Wins: From Kafka to APIs in Minutes
 
Google I/O Extended 2024 Warsaw
Google I/O Extended 2024 WarsawGoogle I/O Extended 2024 Warsaw
Google I/O Extended 2024 Warsaw
 
What's New in Teams Calling, Meetings and Devices April 2024
What's New in Teams Calling, Meetings and Devices April 2024What's New in Teams Calling, Meetings and Devices April 2024
What's New in Teams Calling, Meetings and Devices April 2024
 
Designing for Hardware Accessibility at Comcast
Designing for Hardware Accessibility at ComcastDesigning for Hardware Accessibility at Comcast
Designing for Hardware Accessibility at Comcast
 
IESVE for Early Stage Design and Planning
IESVE for Early Stage Design and PlanningIESVE for Early Stage Design and Planning
IESVE for Early Stage Design and Planning
 
Syngulon - Selection technology May 2024.pdf
Syngulon - Selection technology May 2024.pdfSyngulon - Selection technology May 2024.pdf
Syngulon - Selection technology May 2024.pdf
 
Enterprise Knowledge Graphs - Data Summit 2024
Enterprise Knowledge Graphs - Data Summit 2024Enterprise Knowledge Graphs - Data Summit 2024
Enterprise Knowledge Graphs - Data Summit 2024
 

Simple REST-APIs with Dropwizard and Swagger

  • 2. Motivation 2REST-APIs with Dropwizard & Swagger – VoxxedDays Berlin 2016 – Bernd Schönbach – LeanIX GmbH - Quickly create REST-APIs - Make them testable - Make them deployable with a click - Or even better automatically - Provide Documentation without MS Office - Provide SDK with no extra action needed
  • 3. Overview 3REST-APIs with Dropwizard & Swagger – VoxxedDays Berlin 2016 – Bernd Schönbach – LeanIX GmbH Introduction • About me • About LeanIX Dropwizard • Set Up / Basic Features • Demo • Advanced Features Swagger + Swagger UI • Set Up / Basic Features • Demo • Advanced Features
  • 5. About me 5REST-APIs with Dropwizard & Swagger – VoxxedDays Berlin 2016 – Bernd Schönbach – LeanIX GmbH EnvironmentBernd Schönbach • Est.: 1982 • First Language: PHP (2001) • Second Language: Java (2010) • Java-Dev. @leanIX: 2015 -
  • 6. LeanIX was born, since pragmatic solutions for IT Architecture Management did not exist 6REST-APIs with Dropwizard & Swagger – VoxxedDays Berlin 2016 – Bernd Schönbach – LeanIX GmbH Jörg G. Beyer André Christ Management-Team & FounderLeanIX GmbH • Headquarter: Bonn • Founded: 01/2012 • Launch: 08/2012 • 4 years Management Consulting @ DHL • 8 years Freelancer Software Design & Architecture • Speaker & Author for Software Architecture • 10 years IT Leadership @ DHL, e.g. global CIO • 4 years MD for newly established IT Management Consulting • 10 years Consulting: Andersen & self-employed
  • 7. LeanIX helps companies to manage and optimize their IT Architectures 7REST-APIs with Dropwizard & Swagger – VoxxedDays Berlin 2016 – Bernd Schönbach – LeanIX GmbH Current IT Architecture Create Transparency Optimize IT Architecture • Missing information (e.g. interfaces, technologies) • Hard to introduce new products & sales channels • High costs and risks • Import existing data into LeanIX (via Excel or API) • Invite experts to share their knowledge • Use best-practice reports to identify issues • Define target architecture and roadmaps Learn more: https://www.leanix.net/en/product/index
  • 8. LeanIX is a web-based platform to capture and share knowledge about IT 8REST-APIs with Dropwizard & Swagger – VoxxedDays Berlin 2016 – Bernd Schönbach – LeanIX GmbH Fact Sheets & Tagging Context-based Search API, Import & Export Comments & Threads IT Inventory Collaboration Platform Interactive Reporting Activity Stream & Notifications Subscriptions Print & Export (PDF) Best Practice Reports Interactive Adaption Learn more: https://www.leanix.net/en/product/index
  • 9. Market leading companies already use LeanIX 9 Media Insurance Industry e-Commerce Telecoms Chemical Advisory Government Manufacturing Logistics Education Health Energy See more: https://www.leanix.net/en/customers/index
  • 11. Dropwizard 11REST-APIs with Dropwizard & Swagger – VoxxedDays Berlin 2016 – Bernd Schönbach – LeanIX GmbH Live Demo Overview What is it? The Basics Advanced Features • Java Framework for RESTful Web Services • Quick Startup (few seconds) • Completely configurable • Current Version: 0.9.2 (we will be using 0.9.1)
  • 12. Dropwizard 12REST-APIs with Dropwizard & Swagger – VoxxedDays Berlin 2016 – Bernd Schönbach – LeanIX GmbH Live Demo Overview What is it? The Basics Advanced Features • Framework Contents: • Jetty for HTTP • Jersey for REST • Jackson for JSON transformation • Hibernate for DB Access • Other usefull inclusions • Metrics • Liquibase • Slf4j and Logback • and much more...
  • 13. Dropwizard 13REST-APIs with Dropwizard & Swagger – VoxxedDays Berlin 2016 – Bernd Schönbach – LeanIX GmbH First Steps: What is it? The Basics Advanced Features • Create Maven Project • Add dependency to dropwizard • Configure Maven Shade Plugin • Add configuration file (optional) • Start coding
  • 14. Dropwizard 14REST-APIs with Dropwizard & Swagger – VoxxedDays Berlin 2016 – Bernd Schönbach – LeanIX GmbH Add dependency to pom.xml Standard way (dropwizard only) What is it? The Basics Advanced Features <properties> <dropwizard.version>0.9.1</dropwizard.version> </properties> Step 1: Step 2: <dependencies> <dependency> <groupId>io.dropwizard</groupId> <artifactId>dropwizard-core</artifactId> <version>${dropwizard.version}</version> </dependency> </dependencies>
  • 15. Dropwizard 15REST-APIs with Dropwizard & Swagger – VoxxedDays Berlin 2016 – Bernd Schönbach – LeanIX GmbH Add dependency to pom.xml Our way (Swagger & Dropwizard together) What is it? The Basics Advanced Features <properties> <dropwizard.version>0.9.1-1</dropwizard.version> </properties> Step 1: Step 2: <dependencies> <dependency> <groupId>com.smoketurner</groupId> <artifactId>dropwizard-swagger</artifactId> <version>${dropwizard.version} </version> </dependency> </dependencies>
  • 16. Dropwizard 16REST-APIs with Dropwizard & Swagger – VoxxedDays Berlin 2016 – Bernd Schönbach – LeanIX GmbH Configure Maven Shade Plugin What is it? The Basics Advanced Features <plugin> <artifactId>maven-shade-plugin</artifactId> <version>2.4.1</version> <executions> <execution> <phase>package</phase> <goals> <goal>shade</goal> </goals> <configuration combine.children="append"> <createDependencyReducedPom> true </createDependencyReducedPom> <outputFile>target/voxxed-test.jar</outputFile> [...] </configuration> </execution> </executions> </plugin>
  • 18. Dropwizard 18REST-APIs with Dropwizard & Swagger – VoxxedDays Berlin 2016 – Bernd Schönbach – LeanIX GmbH Configure your Application What is it? The Basics Advanced Features config.yml server: applicationConnectors: type: http port: 1337 adminConnectors: type: http port: $env:ADMIN_PORT:1338 Logging: level: INFO FooBar: Value
  • 19. Dropwizard 19REST-APIs with Dropwizard & Swagger – VoxxedDays Berlin 2016 – Bernd Schönbach – LeanIX GmbH Resource Methods and Paths What is it? The Basics Advanced Features @Path(“persons”) public class PersonResource { @GET public String getPersons () {[…]} @PUT public String updatePerson() {[…]} @POST public String createPerson() {[…]} @DELETE public String deletePerson() {[…]} URL: localhost:1337/persons @GET @Path("/address"} public String getPersonAddress() {[…]} URL: localhost:1337/persons/address
  • 20. Dropwizard 20REST-APIs with Dropwizard & Swagger – VoxxedDays Berlin 2016 – Bernd Schönbach – LeanIX GmbH Query and Path Params What is it? The Basics Advanced Features Task 1: Search an Entity. URL: http://localhost:1337/persons?name=adam Task 2: Retrieve an Entity: URL: http://localhost:1337/persons/1234/ Query Parameters public class PersonResource { @GET public String getPerson( @QueryParam(“name”) String name ) {[…]} Path Parameters public class PersonResource { @GET @Path(“/{id}”) public String getPersonById( @PathParam(“id”) String id ) {[…]}
  • 21. Dropwizard 21REST-APIs with Dropwizard & Swagger – VoxxedDays Berlin 2016 – Bernd Schönbach – LeanIX GmbH Response Types What is it? The Basics Advanced Features Return and retrieve JSON @Produces(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON) public class PersonResource { @GET public String getPerson ( @QueryParam(“name”) String name ) {[…]} @Produces(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON) public class PersonResource { @GET public String getPerson ( @QueryParam(“name”) String name ) {[…]} @GET @Path(“xml”) @Produces(MediaType.APPLICATION_XML) public String getPersonXml (){ […] }
  • 22. Dropwizard 22REST-APIs with Dropwizard & Swagger – VoxxedDays Berlin 2016 – Bernd Schönbach – LeanIX GmbH What is it? The Basics Advanced Features Advanced Features - HATEOAS - Validators and Defaults for Query Parameters - Authentication Handling
  • 23. Dropwizard 23REST-APIs with Dropwizard & Swagger – VoxxedDays Berlin 2016 – Bernd Schönbach – LeanIX GmbH Pimping your Response (HATEOAS) - Add Meta Information to Response Data - Provide Links to allow automated traversal (by machines) { data: [{…},…,{…}] size: 10 total: 150 links: { next: “/persons/page=2&limit=10”, current: “/persons/page=1&limit=10”, previous: null } } What is it? The Basics Advanced Features
  • 24. Dropwizard 24REST-APIs with Dropwizard & Swagger – VoxxedDays Berlin 2016 – Bernd Schönbach – LeanIX GmbH Pimping your Response (HATEOAS) Response Objects What is it? The Basics Advanced Features public class BasicResponse { protected ResponseStatus status = ResponseStatus.OK; protected String type; protected String message; protected Long total; […] } public class PersonResponse extends BasicResponse { protected Person data; protected Links links; public class Links { protected String next; protected String previous; protected String current; } }
  • 25. Dropwizard 25REST-APIs with Dropwizard & Swagger – VoxxedDays Berlin 2016 – Bernd Schönbach – LeanIX GmbH Pimping your Response (HATEOAS) Option B: Jersey Links What is it? The Basics Advanced Features public void run(AppConfig conf, Environment env) throws Ex { environment.jersey().getResourceConfig() .packages(getClass().getPackage().getName()) .register(DeclarativeLinkingFeature.class); } App.java - Add dependency to jersey-server-linking - Register in run function of App.java - Add @Link or @Ref Annotations For further Information see: https://jersey.java.net/documentation/1.19/linking.html
  • 26. Dropwizard 26REST-APIs with Dropwizard & Swagger – VoxxedDays Berlin 2016 – Bernd Schönbach – LeanIX GmbH Validators and Defaults for Query Parameters What is it? The Basics Advanced Features public class PersonResource { @GET public String getPerson ( @QueryParam(“name”) String name ) {[…]} public class PersonResource { @GET public String getPerson ( @QueryParam(“name”) @NotEmpty String name ) {[…]} Validating: Supplied by Hibernate Validator @NotNull @Min(Integer); @Max(Integer) @Size(min = Integer, max = Integer) @Future, @Past @Pattern(regex= String) @Valid
  • 27. Dropwizard 27REST-APIs with Dropwizard & Swagger – VoxxedDays Berlin 2016 – Bernd Schönbach – LeanIX GmbH Authentication Handling What is it? The Basics Advanced Features Step 1: Create Authentication Provider: public class ExampleAuthenticator implements Authenticator<BasicCredentials, User> { @Override public Optional<User> authenticate( BasicCredentials credentials ) throws AuthenticationException { if ("secret".equals(credentials.getPassword())) { return Optional.of(new User(credentials.getUsername())); } return Optional.absent(); } }
  • 28. Dropwizard 28REST-APIs with Dropwizard & Swagger – VoxxedDays Berlin 2016 – Bernd Schönbach – LeanIX GmbH Authentication Handling What is it? The Basics Advanced Features Step 2: Register Authentication Provider: public void run(AppConfig conf, Environment env) throws Ex { environment.jersey().register( new AuthDynamicFeature( new BasicCredentialAuthFilter.Builder<User>() .setAuthenticator(new ExampleAuthenticator()) .setRealm("SUPER SECRET STUFF") .buildAuthFilter() ) ); environment.jersey().register( RolesAllowedDynamicFeature.class ); environment.jersey().register( new AuthValueFactoryProvider.Binder<>(User.class) ); }
  • 29. Dropwizard 29REST-APIs with Dropwizard & Swagger – VoxxedDays Berlin 2016 – Bernd Schönbach – LeanIX GmbH Authentication Handling What is it? The Basics Advanced Features Step 3: Use Auth Parameter: public class PersonResource { @GET public String getPerson ( @QueryParam(“name”) @NotEmpty String name, @Auth User auth ) { […] } }
  • 31. Swagger 31REST-APIs with Dropwizard & Swagger – VoxxedDays Berlin 2016 – Bernd Schönbach – LeanIX GmbH Swagger + Swagger UI What is it? The Basics Advanced Features - Simple documentation for REST APIs - Allows automatic SDK Generation - Nice and interactive User Interface
  • 32. 32
  • 33. Swagger Workflow 33REST-APIs with Dropwizard & Swagger – VoxxedDays Berlin 2016 – Bernd Schönbach – LeanIX GmbH JSON Specification HTML API UI SDK Generation Code Annotation
  • 35. Swagger 35REST-APIs with Dropwizard & Swagger – VoxxedDays Berlin 2016 – Bernd Schönbach – LeanIX GmbH Basic Annotations What is it? The Basics Advanced Features @Api(“Description”) @ApiResponse @ApiResponses @ApiOperation( value = String, notes = String, response = Class, responseContainer = String ) @ApiParam() @DefaultValue(mixed)
  • 36. Swagger 36REST-APIs with Dropwizard & Swagger – VoxxedDays Berlin 2016 – Bernd Schönbach – LeanIX GmbH Basic Annotations What is it? The Basics Advanced Features @ApiParam( name = String, value = String, defaultValue = String, required = Boolean, allowableValues = String, example= String, hidden = Boolean )
  • 37. Swagger 37REST-APIs with Dropwizard & Swagger – VoxxedDays Berlin 2016 – Bernd Schönbach – LeanIX GmbH Further Annotations What is it? The Basics Advanced Features @ApiModel( value= String, description= String ) @ApiModelProperty( value = String, allowableValues= String ) @Contact @License
  • 38. Swagger 38REST-APIs with Dropwizard & Swagger – VoxxedDays Berlin 2016 – Bernd Schönbach – LeanIX GmbH Live Demo Advanced Features SDK Generation What is it? The Basics Advanced Features Example for PHP and Java: https://github.com/leanix/swagger-demo-codegen Configuration for that: https://goo.gl/plH6pB
  • 39. Thank you! Learn More about LeanIX Share on LinkedIn http://bit.ly/LeanIXDemoS Request free demo http://bit.ly/LeanIXDemoS
  • 41. Sources REST-APIs with Dropwizard & Swagger – VoxxedDays Berlin 2016 – Bernd Schönbach – LeanIX GmbH • Dropwizard: http://www.dropwizard.io/ • Swagger: http://swagger.io/ • Swagger-UI: http://swagger.io/swagger-ui/ • Hibernate Validator: http://hibernate.org/validator/ • Dropwizard Swagger Package: https://github.com/smoketurner/dropwizard-swagger
  • 42. Slides will be available at REST-APIs with Dropwizard & Swagger – VoxxedDays Berlin 2016 – Bernd Schönbach – LeanIX GmbH LeanIX Website: https://www.leanix.net/ LeanIX Blog: http://blog.leanix.net/ Slideshare: http://slideshare.net/leanIX_net/ Share on LinkedIn