SlideShare a Scribd company logo
API-First
development
From specification to code and back
Photo by Edho Pratama on Unsplash
Your host today
• Vasco Veloso
• Working in software development since 1996.
• Currently interested in designing software systems
and giving back to the community.
• Author and speaker.
• Portuguese living in the Netherlands.
linkedin.com/in/vascoveloso @vveloso
API-first design
The interface specification comes first.
• Dependencies are discovered.
• Data flows become apparent.
• Data needs can be challenged.
• Great input for threat modelling sessions.
3 Photo by Med Badr Chemmaoui on Unsplash
The problem…
There are many different ways to capture interface designs...
… that are not technical in nature …
… and all require further translation before implementation!
4
The problem…
Many API specifications have little value
• The interface is not complete.
• Examples are missing.
• Data formats or constraints are not defined.
• The specification is outdated.
• Code has changed but the specification did
not.
• There is little connection with the implementation.
5 Photo by Brett Jordan on Unsplash
API-First
Development
Photo by Andrew George on Unsplash
7
API-first development
The interface specification comes first.
Share
Control
Review
Stakeholders
CI/CD
8
API-first development
Capability enabler
cf. 2019 Accelerate State of DevOps Report (DORA)
✅
✅
9
API-first development
Teams with quality documentation are…
cf. 2020 Accelerate State of DevOps Report (DORA)
API-first development
The interface specification needs to be complete.
• All inputs are present.
• Data is properly described.
• Descriptions and examples are included.
Code needs to be generated from the
specification.
• Generate the server interface.
• Generate client code.
10
Photo
by
Julia
Joppien
on
Unsplash
API-first development
Advantages:
• The API specification is the single source of
truth.
• Code and specification are always in sync.
• Specification is good enough to generate code?
• Then it’s good enough to be used for
testing!
• Automatic implementation validation becomes
possible.
11 Photo by Glenn Carstens-Peters on Unsplash
 OpenAPI plugin
 Restler
 Schemathesis
12
API-first development
High-level workflow for developing the server:
Design API
Write OpenAPI
specification
Generate code
Implement & test
business rules
Deploy
Workflow
Refinement
Validate
implementation
Imagine a Java
service using
Spring…
Photo by Scott Graham on Unsplash
… with two operations …
paths:
'/hello':
get:
summary: 'Retrieve a greeting.'
operationId: 'getHelloWorld'
tags:
- "helloWorld"
responses:
'200':
description: 'OK: Returning a greeting.'
schema:
$ref: '#/definitions/Greeting'
'500':
description: 'Internal Server Error'
schema:
$ref: '#/definitions/ResponseError’
put:
summary: 'Set the greeting.'
operationId: 'putHelloWorld'
parameters:
- in: body
name: greeting
schema:
$ref: '#/definitions/Greeting'
required: true
description: 'The new greeting definition.'
tags:
- "helloWorld"
responses:
'200':
description: 'OK: The greeting was stored.'
schema:
$ref: '#/definitions/Greeting'
'500':
description: 'Internal Server Error'
schema:
$ref: '#/definitions/ResponseError'
… and two object definitions …
definitions:
ResponseError:
type: object
properties:
code:
type: string
example: 'E-1234'
description: 'Internal error code.'
required:
- code
Greeting:
type: object
properties:
text:
type: string
pattern: '[0-9a-z]'
maxLength: 100
example: 'Hello'
description: 'The greeting text.'
required:
- text
… using Maven with the OpenAPI plugin …
<plugin>
<groupId>org.openapitools</groupId>
<artifactId>openapi-generator-maven-plugin</artifactId>
<version>5.1.0</version>
<executions>
<execution>
<id>api-generation</id>
<goals><goal>generate</goal></goals>
<configuration>
<inputSpec>
${project.basedir}/src/main/openapi/spec.yaml
</inputSpec>
<output>${project.basedir}/gensrc</output>
<generatorName>spring</generatorName>
<modelPackage>api.example.model</modelPackage>
<apiPackage>api.example.resource</apiPackage>
<configOptions>
<interfaceOnly>true</interfaceOnly>
<dateLibrary>java8</dateLibrary>
<useTags>true</useTags>
</configOptions>
</configuration>
</execution>
</executions>
</plugin>
… generated an interface definition …
/**
* PUT /hello : Set the greeting.
*
* @param greeting The new greeting definition. (required)
* @return OK: The greeting was stored. (status code 200)
* or Internal Server Error: something has gone wrong. (status code 500)
*/
@ApiOperation(value = "Set the greeting.", nickname = "putHelloWorld", notes = "", response =
Greeting.class, tags={ "helloWorld", })
@ApiResponses(value = {
@ApiResponse(code = 200, message = "OK: The greeting was stored.", response = Greeting.class),
@ApiResponse(code = 500, message = "Internal Server Error: something has gone wrong.", response =
ResponseError.class) })
@PutMapping(
value = "/hello",
produces = { "application/json" },
consumes = { "application/json" }
)
default ResponseEntity<Greeting> putHelloWorld(@ApiParam(value = "The new greeting definition."
,required=true ) @Valid @RequestBody Greeting greeting) {
return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED);
}
… with objects that can be validated.
public class Greeting {
@JsonProperty("text")
private String text;
public Greeting text(String text) {
this.text = text;
return this;
}
/**
* The greeting text.
* @return text
*/
@ApiModelProperty(example = "Hello", required = true, value = "The greeting text.")
@NotNull
@Pattern(regexp="[0-9a-z]") @Size(max=100)
public String getText() { return text; }
public void setText(String text) { this.text = text; }
}
Flipping it
around
Photo by Persnickety Prints on Unsplash
Flipping it around
• Requires a prototype-first
approach.
• Implies evolving the prototype!
• The specification slides to the
background.
20 Photo by Mark Konig on Unsplash
Flipping it around
• It is easier to use validations, data
structures or types that can’t be
represented in the specification.
• Focus shifts easily to the
implementation instead of the
API.
• API discussions may turn into
coding arguments.
21
Photo by Huey Images on Unsplash
Flipping it around
• It is easier to forget to add
annotations to the code.
• Details become absent from the
specification.
• The specification loses value.
22 Photo by Peter Pryharski on Unsplash
Now what?
Photo by Tom Ramalho on Unsplash
Key takeaways
24
Build
Build the OpenAPI file first
• Place all possible validations in the
OpenAPI file.
Generate
Generate code second
• API model DTOs are generated.
• Controller interface(s) are generated.
• Validations are translated into bean
validations.
• Default implementation ready with an
HTTP 501 response.
Extend
Extend the interface(s) with
the real controller(s).
Thank you!
Photo by Camylla Battani on Unsplash
linkedin.com/in/vascoveloso
@vveloso

More Related Content

PPTX
REST API Design & Development
PDF
Microservices Design Patterns | Edureka
PPTX
SOA Course - Next Generation
PPTX
Api types
PPTX
REST-API introduction for developers
PDF
API Management Solution Powerpoint Presentation Slides
PPTX
Api gateway in microservices
PPTX
API Management Part 1 - An Introduction to Azure API Management
REST API Design & Development
Microservices Design Patterns | Edureka
SOA Course - Next Generation
Api types
REST-API introduction for developers
API Management Solution Powerpoint Presentation Slides
Api gateway in microservices
API Management Part 1 - An Introduction to Azure API Management

What's hot (20)

PPTX
API Design- Best Practices
PPTX
What is an API Gateway?
PDF
API for Beginners
PPTX
REST & RESTful Web Services
PPT
Introduction to the Web API
PPTX
Api-First service design
PPTX
Get Started with ReactJS 18 Development Services_ New Features and Updates.pptx
PPTX
Microservices Architecture & Testing Strategies
PDF
Node.js - #1 - Introdução - Rodrigo Branas
PDF
Api presentation
PPTX
GraphQL API Gateway and microservices
PPTX
API Presentation
PPTX
react-slides.pptx
PDF
API Security Best Practices & Guidelines
PDF
Wroclaw GraphQL - GraphQL in Java
PPTX
Springboot Microservices
PPTX
JIRA 업무 생산성 향상 및 프로젝트 관리
PPSX
Rest api standards and best practices
PPTX
API as-a-Product with Azure API Management (APIM)
API Design- Best Practices
What is an API Gateway?
API for Beginners
REST & RESTful Web Services
Introduction to the Web API
Api-First service design
Get Started with ReactJS 18 Development Services_ New Features and Updates.pptx
Microservices Architecture & Testing Strategies
Node.js - #1 - Introdução - Rodrigo Branas
Api presentation
GraphQL API Gateway and microservices
API Presentation
react-slides.pptx
API Security Best Practices & Guidelines
Wroclaw GraphQL - GraphQL in Java
Springboot Microservices
JIRA 업무 생산성 향상 및 프로젝트 관리
Rest api standards and best practices
API as-a-Product with Azure API Management (APIM)
Ad

Similar to API-first development (20)

PDF
Maciej Treder "Server-side rendering with Angular—be faster and more SEO, CDN...
PPT
Play framework
PPTX
REST API for your WP7 App
PDF
Cqrs api v2
PDF
WebNet Conference 2012 - Designing complex applications using html5 and knock...
PPTX
AngularJS with TypeScript and Windows Azure Mobile Services
PPTX
Node.js Patterns for Discerning Developers
PDF
Data models in Angular 1 & 2
PPTX
Alberto Maria Angelo Paro - Isomorphic programming in Scala and WebDevelopmen...
PPTX
I Know It Was MEAN, But I Cut the Cord to LAMP Anyway
PDF
09 - express nodes on the right angle - vitaliy basyuk - it event 2013 (5)
PDF
Supercharging WordPress Development - Wordcamp Brighton 2019
PPTX
I Know It Was MEAN, But I Cut the Cord to LAMP Anyway
PDF
Scalable web application architecture
PPTX
Developing Lightning Components for Communities.pptx
PDF
From Backbone to Ember and Back(bone) Again
PDF
Automating Performance Monitoring at Microsoft
PDF
Effectively Testing Services - Burlington Ruby Conf
PDF
JCD 2013 OCM Java Developer
Maciej Treder "Server-side rendering with Angular—be faster and more SEO, CDN...
Play framework
REST API for your WP7 App
Cqrs api v2
WebNet Conference 2012 - Designing complex applications using html5 and knock...
AngularJS with TypeScript and Windows Azure Mobile Services
Node.js Patterns for Discerning Developers
Data models in Angular 1 & 2
Alberto Maria Angelo Paro - Isomorphic programming in Scala and WebDevelopmen...
I Know It Was MEAN, But I Cut the Cord to LAMP Anyway
09 - express nodes on the right angle - vitaliy basyuk - it event 2013 (5)
Supercharging WordPress Development - Wordcamp Brighton 2019
I Know It Was MEAN, But I Cut the Cord to LAMP Anyway
Scalable web application architecture
Developing Lightning Components for Communities.pptx
From Backbone to Ember and Back(bone) Again
Automating Performance Monitoring at Microsoft
Effectively Testing Services - Burlington Ruby Conf
JCD 2013 OCM Java Developer
Ad

Recently uploaded (20)

PPTX
Fluid Mechanics, Module 3: Basics of Fluid Mechanics
PPTX
Strings in CPP - Strings in C++ are sequences of characters used to store and...
PPT
Drone Technology Electronics components_1
PPTX
additive manufacturing of ss316l using mig welding
PPTX
UNIT-1 - COAL BASED THERMAL POWER PLANTS
PPTX
Geodesy 1.pptx...............................................
PPTX
Welding lecture in detail for understanding
PPTX
OOP with Java - Java Introduction (Basics)
PDF
BMEC211 - INTRODUCTION TO MECHATRONICS-1.pdf
PPTX
Internet of Things (IOT) - A guide to understanding
PDF
July 2025 - Top 10 Read Articles in International Journal of Software Enginee...
PDF
SM_6th-Sem__Cse_Internet-of-Things.pdf IOT
PPTX
CH1 Production IntroductoryConcepts.pptx
PDF
Arduino robotics embedded978-1-4302-3184-4.pdf
PDF
Operating System & Kernel Study Guide-1 - converted.pdf
PPTX
Sustainable Sites - Green Building Construction
PPT
Project quality management in manufacturing
PPTX
web development for engineering and engineering
PPTX
MET 305 2019 SCHEME MODULE 2 COMPLETE.pptx
PDF
Model Code of Practice - Construction Work - 21102022 .pdf
Fluid Mechanics, Module 3: Basics of Fluid Mechanics
Strings in CPP - Strings in C++ are sequences of characters used to store and...
Drone Technology Electronics components_1
additive manufacturing of ss316l using mig welding
UNIT-1 - COAL BASED THERMAL POWER PLANTS
Geodesy 1.pptx...............................................
Welding lecture in detail for understanding
OOP with Java - Java Introduction (Basics)
BMEC211 - INTRODUCTION TO MECHATRONICS-1.pdf
Internet of Things (IOT) - A guide to understanding
July 2025 - Top 10 Read Articles in International Journal of Software Enginee...
SM_6th-Sem__Cse_Internet-of-Things.pdf IOT
CH1 Production IntroductoryConcepts.pptx
Arduino robotics embedded978-1-4302-3184-4.pdf
Operating System & Kernel Study Guide-1 - converted.pdf
Sustainable Sites - Green Building Construction
Project quality management in manufacturing
web development for engineering and engineering
MET 305 2019 SCHEME MODULE 2 COMPLETE.pptx
Model Code of Practice - Construction Work - 21102022 .pdf

API-first development

  • 1. API-First development From specification to code and back Photo by Edho Pratama on Unsplash
  • 2. Your host today • Vasco Veloso • Working in software development since 1996. • Currently interested in designing software systems and giving back to the community. • Author and speaker. • Portuguese living in the Netherlands. linkedin.com/in/vascoveloso @vveloso
  • 3. API-first design The interface specification comes first. • Dependencies are discovered. • Data flows become apparent. • Data needs can be challenged. • Great input for threat modelling sessions. 3 Photo by Med Badr Chemmaoui on Unsplash
  • 4. The problem… There are many different ways to capture interface designs... … that are not technical in nature … … and all require further translation before implementation! 4
  • 5. The problem… Many API specifications have little value • The interface is not complete. • Examples are missing. • Data formats or constraints are not defined. • The specification is outdated. • Code has changed but the specification did not. • There is little connection with the implementation. 5 Photo by Brett Jordan on Unsplash
  • 7. 7 API-first development The interface specification comes first. Share Control Review Stakeholders CI/CD
  • 8. 8 API-first development Capability enabler cf. 2019 Accelerate State of DevOps Report (DORA) ✅ ✅
  • 9. 9 API-first development Teams with quality documentation are… cf. 2020 Accelerate State of DevOps Report (DORA)
  • 10. API-first development The interface specification needs to be complete. • All inputs are present. • Data is properly described. • Descriptions and examples are included. Code needs to be generated from the specification. • Generate the server interface. • Generate client code. 10 Photo by Julia Joppien on Unsplash
  • 11. API-first development Advantages: • The API specification is the single source of truth. • Code and specification are always in sync. • Specification is good enough to generate code? • Then it’s good enough to be used for testing! • Automatic implementation validation becomes possible. 11 Photo by Glenn Carstens-Peters on Unsplash
  • 12.  OpenAPI plugin  Restler  Schemathesis 12 API-first development High-level workflow for developing the server: Design API Write OpenAPI specification Generate code Implement & test business rules Deploy Workflow Refinement Validate implementation
  • 13. Imagine a Java service using Spring… Photo by Scott Graham on Unsplash
  • 14. … with two operations … paths: '/hello': get: summary: 'Retrieve a greeting.' operationId: 'getHelloWorld' tags: - "helloWorld" responses: '200': description: 'OK: Returning a greeting.' schema: $ref: '#/definitions/Greeting' '500': description: 'Internal Server Error' schema: $ref: '#/definitions/ResponseError’ put: summary: 'Set the greeting.' operationId: 'putHelloWorld' parameters: - in: body name: greeting schema: $ref: '#/definitions/Greeting' required: true description: 'The new greeting definition.' tags: - "helloWorld" responses: '200': description: 'OK: The greeting was stored.' schema: $ref: '#/definitions/Greeting' '500': description: 'Internal Server Error' schema: $ref: '#/definitions/ResponseError'
  • 15. … and two object definitions … definitions: ResponseError: type: object properties: code: type: string example: 'E-1234' description: 'Internal error code.' required: - code Greeting: type: object properties: text: type: string pattern: '[0-9a-z]' maxLength: 100 example: 'Hello' description: 'The greeting text.' required: - text
  • 16. … using Maven with the OpenAPI plugin … <plugin> <groupId>org.openapitools</groupId> <artifactId>openapi-generator-maven-plugin</artifactId> <version>5.1.0</version> <executions> <execution> <id>api-generation</id> <goals><goal>generate</goal></goals> <configuration> <inputSpec> ${project.basedir}/src/main/openapi/spec.yaml </inputSpec> <output>${project.basedir}/gensrc</output> <generatorName>spring</generatorName> <modelPackage>api.example.model</modelPackage> <apiPackage>api.example.resource</apiPackage> <configOptions> <interfaceOnly>true</interfaceOnly> <dateLibrary>java8</dateLibrary> <useTags>true</useTags> </configOptions> </configuration> </execution> </executions> </plugin>
  • 17. … generated an interface definition … /** * PUT /hello : Set the greeting. * * @param greeting The new greeting definition. (required) * @return OK: The greeting was stored. (status code 200) * or Internal Server Error: something has gone wrong. (status code 500) */ @ApiOperation(value = "Set the greeting.", nickname = "putHelloWorld", notes = "", response = Greeting.class, tags={ "helloWorld", }) @ApiResponses(value = { @ApiResponse(code = 200, message = "OK: The greeting was stored.", response = Greeting.class), @ApiResponse(code = 500, message = "Internal Server Error: something has gone wrong.", response = ResponseError.class) }) @PutMapping( value = "/hello", produces = { "application/json" }, consumes = { "application/json" } ) default ResponseEntity<Greeting> putHelloWorld(@ApiParam(value = "The new greeting definition." ,required=true ) @Valid @RequestBody Greeting greeting) { return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); }
  • 18. … with objects that can be validated. public class Greeting { @JsonProperty("text") private String text; public Greeting text(String text) { this.text = text; return this; } /** * The greeting text. * @return text */ @ApiModelProperty(example = "Hello", required = true, value = "The greeting text.") @NotNull @Pattern(regexp="[0-9a-z]") @Size(max=100) public String getText() { return text; } public void setText(String text) { this.text = text; } }
  • 19. Flipping it around Photo by Persnickety Prints on Unsplash
  • 20. Flipping it around • Requires a prototype-first approach. • Implies evolving the prototype! • The specification slides to the background. 20 Photo by Mark Konig on Unsplash
  • 21. Flipping it around • It is easier to use validations, data structures or types that can’t be represented in the specification. • Focus shifts easily to the implementation instead of the API. • API discussions may turn into coding arguments. 21 Photo by Huey Images on Unsplash
  • 22. Flipping it around • It is easier to forget to add annotations to the code. • Details become absent from the specification. • The specification loses value. 22 Photo by Peter Pryharski on Unsplash
  • 23. Now what? Photo by Tom Ramalho on Unsplash
  • 24. Key takeaways 24 Build Build the OpenAPI file first • Place all possible validations in the OpenAPI file. Generate Generate code second • API model DTOs are generated. • Controller interface(s) are generated. • Validations are translated into bean validations. • Default implementation ready with an HTTP 501 response. Extend Extend the interface(s) with the real controller(s).
  • 25. Thank you! Photo by Camylla Battani on Unsplash linkedin.com/in/vascoveloso @vveloso