SlideShare uma empresa Scribd logo
1 de 36
Building APIs
with the OpenAPISpec
Dr. Pedro J. Molina
CEOat Metadev @pmolinam
What’s common here?
Library 1
Library 2
Shop N
Service 1
Service 2
Service N
mLab
SendGrid
Plugin N
API
API
API
Ecosystems
Pedro J.Molina
@pmolinam
Agenda
 API Economy
 OpenAPI
 User Cases
 Versioning
 Future
Application Programmer Interface
Services ready for 3er partiesto
consume
Technical Description (dev. oriented)
Promotes system integration by
clear contracts durable intime
API Economy
APIs define plataforms.
Twitter, Twilio, Google Mapsas API samples.
You can’t win without anecosystem.
You can’t have an ecosystem without an API.
First one take it all  market share
API
API as a contract with customers
Language agnostic APIs
1. CORBA >> C+ IDL
2. SOA >> XML + SOAP + WDSL …
3. REST >> JSON + HTTP
OpenAPI Initiative
De facto standard (previously: Swagger)
Linux Foundation https://www.openapis.org
Formal contract description for a RESTAPI useful forboth
humans and machines.
Contract described in JSON orYAML
OpenAPI Initiative
http://editor.swagger.io
http://petstore.swagger.io
Tooling
 Editor
 API Explorer
 Validator
https://online.swagger.io/validator
Opensource Generators:
 skeletons for back-ends
 proxies for front-end
http://swagger.io/swagger-codegen
Use cases
1. Legacy API
2. Contract First
3. Service driven
1. Legacy API
API
Document an existing API
Contract creation http://editor.swagger.io
Validation
Results:
 API docs
 SDK generation for clients
1. Legacy API. Sample
Is Nieves a girl’s or boy’s name?
Web service to discoverit:
http://www.jerolba.com/mujeres-y-hombres-y-serverless
GEThttps://us-central1-hombre-o-mujer.cloudfunctions.net/gender?name=nieves
Credits to: Jerónimo López @jerolba
API
1. Legacy API. Contract
API
http://bit.ly/gender-swagger
swagger: '2.0'
info:
version: "1.0.0"
title: Girl or boy.
host: us-central1-hombre-o-mujer.cloudfunctions.net
schemes:
- https
consumes:
- application/json
produces:
- application/json
tags:
- name: Gender
description: Frequency name based API to guest gender.
paths:
/gender:
get:
description: |
Returns the probability base on gender frequency on registed names in
Spain.
parameters:
- name: name
in: query
description: Given name
required: true
type: string
responses:
# Response code
200:
description: Sucessful response
schema:
$ref: "#/definitions/GenderResponse"
404:
description: Not found
schema:
$ref: "#/definitions/GenderNotFoundResponse"
1. Legacy API. Contract
API
totalMale:
type: number
format: int32
totalFemale:
type: number
format: int32
GenderNotFoundResponse:
required:
- name
- gender
properties:
name:
type: string
gender:
type: string
definitions:
GenderResponse:
required:
- name
- gender
- probability
- totalMale
- totalFemale
properties:
name:
type: string
gender:
type: string
probability:
type: number
format: float
1. Legacy API. Contract
API
2. Contract First
Spec is written in firstplace
http://editor.swagger.io
Can generate:
 a skeleton for backend
 a proxy or SDKfor consumers
 enables parallel work on backend and frontend teams.
 contract change can be versioned in a proper way.
API Client
2. Contract First. Available server stacks
2. Contract First. Available front-end stacks
Swagger/code-gen
Migrating fromspec v.2 to v.3
Book about how to extend swagger/code-gen for your
language/stack:
http://bit.ly/codegen101
3. Service Driven
 The Service defines the contract
The OpenAPI spec is generated by a library using reflection over the
service.
Requires taking special care to NOT TO break theAPI compatibility.
Sample: https://openapi3.herokuapp.com
Source: https://github.com/pjmolina/event-backend
API Client
Resources
Maintainer of:
 baucis-swagger2 Generates v.2 contracts for Baucis backends
 https://www.npmjs.com/package/baucis-swagger2
 baucis-openapi3 Generates v.3 contracts for Baucis backends
 https://www.npmjs.com/package/baucis-openapi3
 openapi3-ts TypeScript library forbuilding OpenAPI3 documents
 https://www.npmjs.com/package/openapi3-ts
API Management Tools
API Management Tools
Examples
3scale
Apigee
Mashape Kong
CA 7Layers
Azure API Management
IBM Bluemix API
Management
WSO
 Provides an extra layer in front of your API
 Managed by 3er parties (externalized)
Main features:
 Authentication, Authorization
 Role-based security
 DOSattack protection
 Monetization: pay per use
 Scaling
 Auditing
 Usage metrics, analytics
API Versioning
 Versioning via URL
GET /v1/restaurants?location=SVQ
GET /v2/restaurants?location=SVQ&limit=30
Versioning via parameter
GET /restaurants?location=SVQ&limit=30&v=2
Versioning via headers
GET /restaurants?location=SVQ&limit=30
Version: 2
API Scalability
 Stateless API
 Load-balancer to handletraffic
(e.g. nginx or ha-proxy)
 Distributes traffic toyour API
servers
 DNS, SSLand certs. configured in
the load balancer
lb
api #0
api #1
api #2
443
80
Summing up
OpenAPI is a de-facto standard to manage
APIs
Simplifies consumption and APIintegration
Version 3.0 released in June2017
Roadmap:
Swagger-codegen porting from v.2 to v.3
(work in progress)
Convergence with GooglegRPC
Thx!
@pmolinam
Questions?
@pmolinam
Your ideas inaction
https://metadev.pro | @metad3v
Extra bonus
REST
 REpresentational State Transfer
 Stateless Protocol
 Unique URIs per resource
 Semantic attached to operations/verbs
 GET/PUT/POST/DELETE over HTTP
Hypermedia (navigable)
GET /actors/42
Accept: application/json
200 OK
Content-Type: application/json
{ "id": 42
"name": "Jessica"
"lastname": "Alba"
"filmography": "/films/42"
}
MIME Types
 Declares encoding
Most frequents are:
 JSON
 XML
 HTML
 Plain text
 CSV
application/json
text/xml
text/html
text/plain
text/csv
GET /actors/42
Accept: text/xml
200 OK
Content-Type: text/xml
<actor id="42">
<name>Jessica</name>
<lastname>Alba</lastname>
<filmography
url= "/films/42" />
</actor>
REST Levels
Richarson Maturity Model
http://martinfowler.com/articles/richardsonMaturityModel.html
GET /invoice/217
POST /invoice/  201 Created
 Level 0. HTTP and nothing else (RPC underHTTP)
 Level 1. Resources
 Level 2. Using the semantinc of verbs and HTTP error
codes https://i.stack.imgur.com/whhD1.png
https://httpstatuses.com
Level 3. HypermediaControls <link rel=“lines”
uri=“/factura/217/lineas”/>
HAL
{
“id”: 1234
“name”: “Alice in Wonderland”
“_links”: {
“self”: { “href”: “/book/10”},
“prev”: { “href”: “/book/9”},
“next”: { “href”: “/book/11”},
“action-delete”: {
“verb”: “DELETE”,
“href”: “/book/10”
}
}
}
://

Mais conteúdo relacionado

Semelhante a SVQdotNET: Building APIs with OpenApi

Running the-next-generation-of-cloud-native-applications-using-open-applicati...
Running the-next-generation-of-cloud-native-applications-using-open-applicati...Running the-next-generation-of-cloud-native-applications-using-open-applicati...
Running the-next-generation-of-cloud-native-applications-using-open-applicati...
NaveedAhmad239
 
Running gRPC Services for Serving Legacy API on Kubernetes
Running gRPC Services for Serving Legacy API on KubernetesRunning gRPC Services for Serving Legacy API on Kubernetes
Running gRPC Services for Serving Legacy API on Kubernetes
Sungwon Lee
 

Semelhante a SVQdotNET: Building APIs with OpenApi (20)

Crafting APIs
Crafting APIsCrafting APIs
Crafting APIs
 
apidays LIVE Paris 2021 - Getting started with Event-Driven APis by Hugo Guer...
apidays LIVE Paris 2021 - Getting started with Event-Driven APis by Hugo Guer...apidays LIVE Paris 2021 - Getting started with Event-Driven APis by Hugo Guer...
apidays LIVE Paris 2021 - Getting started with Event-Driven APis by Hugo Guer...
 
API and Platform Strategies to Win in Global and Local Markets
API and Platform Strategies to Win in Global and Local MarketsAPI and Platform Strategies to Win in Global and Local Markets
API and Platform Strategies to Win in Global and Local Markets
 
OpenShift Meetup - Tokyo - Service Mesh and Serverless Overview
OpenShift Meetup - Tokyo - Service Mesh and Serverless OverviewOpenShift Meetup - Tokyo - Service Mesh and Serverless Overview
OpenShift Meetup - Tokyo - Service Mesh and Serverless Overview
 
Api design best practice
Api design best practiceApi design best practice
Api design best practice
 
GlueCon 2018: Are REST APIs Still Relevant Today?
GlueCon 2018: Are REST APIs Still Relevant Today?GlueCon 2018: Are REST APIs Still Relevant Today?
GlueCon 2018: Are REST APIs Still Relevant Today?
 
Model-driven Round-trip Engineering of REST APIs
Model-driven Round-trip Engineering of REST APIsModel-driven Round-trip Engineering of REST APIs
Model-driven Round-trip Engineering of REST APIs
 
7 network programmability concepts api
7 network programmability concepts api7 network programmability concepts api
7 network programmability concepts api
 
2022 APIsecure_Securing APIs with Open Standards
2022 APIsecure_Securing APIs with Open Standards2022 APIsecure_Securing APIs with Open Standards
2022 APIsecure_Securing APIs with Open Standards
 
Running the-next-generation-of-cloud-native-applications-using-open-applicati...
Running the-next-generation-of-cloud-native-applications-using-open-applicati...Running the-next-generation-of-cloud-native-applications-using-open-applicati...
Running the-next-generation-of-cloud-native-applications-using-open-applicati...
 
Build Great Networked APIs with Swift, OpenAPI, and gRPC
Build Great Networked APIs with Swift, OpenAPI, and gRPCBuild Great Networked APIs with Swift, OpenAPI, and gRPC
Build Great Networked APIs with Swift, OpenAPI, and gRPC
 
7 network programmability concepts api
7 network programmability concepts api7 network programmability concepts api
7 network programmability concepts api
 
RefCard API Architecture Strategy
RefCard API Architecture StrategyRefCard API Architecture Strategy
RefCard API Architecture Strategy
 
Implementing OpenAPI and GraphQL services with gRPC
Implementing OpenAPI and GraphQL services with gRPCImplementing OpenAPI and GraphQL services with gRPC
Implementing OpenAPI and GraphQL services with gRPC
 
Running gRPC Services for Serving Legacy API on Kubernetes
Running gRPC Services for Serving Legacy API on KubernetesRunning gRPC Services for Serving Legacy API on Kubernetes
Running gRPC Services for Serving Legacy API on Kubernetes
 
Operator SDK for K8s using Go
Operator SDK for K8s using GoOperator SDK for K8s using Go
Operator SDK for K8s using Go
 
Managing microservices with istio on OpenShift - Meetup
Managing microservices with istio on OpenShift - MeetupManaging microservices with istio on OpenShift - Meetup
Managing microservices with istio on OpenShift - Meetup
 
Web Dev 21-01-2024.pptx
Web Dev 21-01-2024.pptxWeb Dev 21-01-2024.pptx
Web Dev 21-01-2024.pptx
 
Austin API Summit 2018: Are REST APIs Still Relevant Today?
Austin API Summit 2018: Are REST APIs Still Relevant Today?Austin API Summit 2018: Are REST APIs Still Relevant Today?
Austin API Summit 2018: Are REST APIs Still Relevant Today?
 
Are REST APIs Still Relevant Today?
Are REST APIs Still Relevant Today?Are REST APIs Still Relevant Today?
Are REST APIs Still Relevant Today?
 

Último

Último (20)

CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
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
 
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
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
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
 
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
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
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
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 

SVQdotNET: Building APIs with OpenApi

  • 1. Building APIs with the OpenAPISpec Dr. Pedro J. Molina CEOat Metadev @pmolinam
  • 2. What’s common here? Library 1 Library 2 Shop N Service 1 Service 2 Service N mLab SendGrid Plugin N API API API Ecosystems
  • 4. Agenda  API Economy  OpenAPI  User Cases  Versioning  Future
  • 5. Application Programmer Interface Services ready for 3er partiesto consume Technical Description (dev. oriented) Promotes system integration by clear contracts durable intime
  • 6. API Economy APIs define plataforms. Twitter, Twilio, Google Mapsas API samples. You can’t win without anecosystem. You can’t have an ecosystem without an API. First one take it all  market share
  • 7. API API as a contract with customers
  • 8. Language agnostic APIs 1. CORBA >> C+ IDL 2. SOA >> XML + SOAP + WDSL … 3. REST >> JSON + HTTP
  • 9. OpenAPI Initiative De facto standard (previously: Swagger) Linux Foundation https://www.openapis.org Formal contract description for a RESTAPI useful forboth humans and machines. Contract described in JSON orYAML
  • 10.
  • 11. OpenAPI Initiative http://editor.swagger.io http://petstore.swagger.io Tooling  Editor  API Explorer  Validator https://online.swagger.io/validator Opensource Generators:  skeletons for back-ends  proxies for front-end http://swagger.io/swagger-codegen
  • 12. Use cases 1. Legacy API 2. Contract First 3. Service driven
  • 13. 1. Legacy API API Document an existing API Contract creation http://editor.swagger.io Validation Results:  API docs  SDK generation for clients
  • 14. 1. Legacy API. Sample Is Nieves a girl’s or boy’s name? Web service to discoverit: http://www.jerolba.com/mujeres-y-hombres-y-serverless GEThttps://us-central1-hombre-o-mujer.cloudfunctions.net/gender?name=nieves Credits to: Jerónimo López @jerolba API
  • 15. 1. Legacy API. Contract API http://bit.ly/gender-swagger swagger: '2.0' info: version: "1.0.0" title: Girl or boy. host: us-central1-hombre-o-mujer.cloudfunctions.net schemes: - https consumes: - application/json produces: - application/json tags: - name: Gender description: Frequency name based API to guest gender.
  • 16. paths: /gender: get: description: | Returns the probability base on gender frequency on registed names in Spain. parameters: - name: name in: query description: Given name required: true type: string responses: # Response code 200: description: Sucessful response schema: $ref: "#/definitions/GenderResponse" 404: description: Not found schema: $ref: "#/definitions/GenderNotFoundResponse" 1. Legacy API. Contract API
  • 17. totalMale: type: number format: int32 totalFemale: type: number format: int32 GenderNotFoundResponse: required: - name - gender properties: name: type: string gender: type: string definitions: GenderResponse: required: - name - gender - probability - totalMale - totalFemale properties: name: type: string gender: type: string probability: type: number format: float 1. Legacy API. Contract API
  • 18. 2. Contract First Spec is written in firstplace http://editor.swagger.io Can generate:  a skeleton for backend  a proxy or SDKfor consumers  enables parallel work on backend and frontend teams.  contract change can be versioned in a proper way. API Client
  • 19. 2. Contract First. Available server stacks
  • 20. 2. Contract First. Available front-end stacks
  • 21. Swagger/code-gen Migrating fromspec v.2 to v.3 Book about how to extend swagger/code-gen for your language/stack: http://bit.ly/codegen101
  • 22. 3. Service Driven  The Service defines the contract The OpenAPI spec is generated by a library using reflection over the service. Requires taking special care to NOT TO break theAPI compatibility. Sample: https://openapi3.herokuapp.com Source: https://github.com/pjmolina/event-backend API Client
  • 23. Resources Maintainer of:  baucis-swagger2 Generates v.2 contracts for Baucis backends  https://www.npmjs.com/package/baucis-swagger2  baucis-openapi3 Generates v.3 contracts for Baucis backends  https://www.npmjs.com/package/baucis-openapi3  openapi3-ts TypeScript library forbuilding OpenAPI3 documents  https://www.npmjs.com/package/openapi3-ts
  • 25. API Management Tools Examples 3scale Apigee Mashape Kong CA 7Layers Azure API Management IBM Bluemix API Management WSO  Provides an extra layer in front of your API  Managed by 3er parties (externalized) Main features:  Authentication, Authorization  Role-based security  DOSattack protection  Monetization: pay per use  Scaling  Auditing  Usage metrics, analytics
  • 26. API Versioning  Versioning via URL GET /v1/restaurants?location=SVQ GET /v2/restaurants?location=SVQ&limit=30 Versioning via parameter GET /restaurants?location=SVQ&limit=30&v=2 Versioning via headers GET /restaurants?location=SVQ&limit=30 Version: 2
  • 27. API Scalability  Stateless API  Load-balancer to handletraffic (e.g. nginx or ha-proxy)  Distributes traffic toyour API servers  DNS, SSLand certs. configured in the load balancer lb api #0 api #1 api #2 443 80
  • 28. Summing up OpenAPI is a de-facto standard to manage APIs Simplifies consumption and APIintegration Version 3.0 released in June2017 Roadmap: Swagger-codegen porting from v.2 to v.3 (work in progress) Convergence with GooglegRPC
  • 33. REST  REpresentational State Transfer  Stateless Protocol  Unique URIs per resource  Semantic attached to operations/verbs  GET/PUT/POST/DELETE over HTTP Hypermedia (navigable) GET /actors/42 Accept: application/json 200 OK Content-Type: application/json { "id": 42 "name": "Jessica" "lastname": "Alba" "filmography": "/films/42" }
  • 34. MIME Types  Declares encoding Most frequents are:  JSON  XML  HTML  Plain text  CSV application/json text/xml text/html text/plain text/csv GET /actors/42 Accept: text/xml 200 OK Content-Type: text/xml <actor id="42"> <name>Jessica</name> <lastname>Alba</lastname> <filmography url= "/films/42" /> </actor>
  • 35. REST Levels Richarson Maturity Model http://martinfowler.com/articles/richardsonMaturityModel.html GET /invoice/217 POST /invoice/  201 Created  Level 0. HTTP and nothing else (RPC underHTTP)  Level 1. Resources  Level 2. Using the semantinc of verbs and HTTP error codes https://i.stack.imgur.com/whhD1.png https://httpstatuses.com Level 3. HypermediaControls <link rel=“lines” uri=“/factura/217/lineas”/>
  • 36. HAL { “id”: 1234 “name”: “Alice in Wonderland” “_links”: { “self”: { “href”: “/book/10”}, “prev”: { “href”: “/book/9”}, “next”: { “href”: “/book/11”}, “action-delete”: { “verb”: “DELETE”, “href”: “/book/10” } } } ://