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?

Was ist angesagt? (20)

Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDB
 
Introduction to elasticsearch
Introduction to elasticsearchIntroduction to elasticsearch
Introduction to elasticsearch
 
Anatomy of a Spring Boot App with Clean Architecture - Spring I/O 2023
Anatomy of a Spring Boot App with Clean Architecture - Spring I/O 2023Anatomy of a Spring Boot App with Clean Architecture - Spring I/O 2023
Anatomy of a Spring Boot App with Clean Architecture - Spring I/O 2023
 
Clean Architecture
Clean ArchitectureClean Architecture
Clean Architecture
 
Bitbucket
BitbucketBitbucket
Bitbucket
 
Clean code
Clean codeClean code
Clean code
 
Introduction to gradle
Introduction to gradleIntroduction to gradle
Introduction to gradle
 
Building with Gradle
Building with GradleBuilding with Gradle
Building with Gradle
 
ECMA Script
ECMA ScriptECMA Script
ECMA Script
 
Java Server Faces (JSF) - Basics
Java Server Faces (JSF) - BasicsJava Server Faces (JSF) - Basics
Java Server Faces (JSF) - Basics
 
MongoDB Fundamentals
MongoDB FundamentalsMongoDB Fundamentals
MongoDB Fundamentals
 
Hibernate presentation
Hibernate presentationHibernate presentation
Hibernate presentation
 
Spring boot introduction
Spring boot introductionSpring boot introduction
Spring boot introduction
 
Large Table Partitioning with PostgreSQL and Django
 Large Table Partitioning with PostgreSQL and Django Large Table Partitioning with PostgreSQL and Django
Large Table Partitioning with PostgreSQL and Django
 
SQL to Hive Cheat Sheet
SQL to Hive Cheat SheetSQL to Hive Cheat Sheet
SQL to Hive Cheat Sheet
 
Solid Principles
Solid PrinciplesSolid Principles
Solid Principles
 
Learn O11y from Grafana ecosystem.
Learn O11y from Grafana ecosystem.Learn O11y from Grafana ecosystem.
Learn O11y from Grafana ecosystem.
 
Git and Github Session
Git and Github SessionGit and Github Session
Git and Github Session
 
Migrating to Java 11
Migrating to Java 11Migrating to Java 11
Migrating to Java 11
 
Avoiding Deadlocks: Lessons Learned with Zephyr Health Using Neo4j and MongoD...
Avoiding Deadlocks: Lessons Learned with Zephyr Health Using Neo4j and MongoD...Avoiding Deadlocks: Lessons Learned with Zephyr Health Using Neo4j and MongoD...
Avoiding Deadlocks: Lessons Learned with Zephyr Health Using Neo4j and MongoD...
 

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

Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Victor Rentea
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 

Kürzlich hochgeladen (20)

Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUKSpring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
Cyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdfCyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdf
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 

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