OpenAPI es un estándar emergente para crear, administrar y consumir API REST. Conocido anteriormente como Swagger, en el último año ha sido adoptado por la Linux Foundation y obtuvo el apoyo de compañías como Google, Microsoft, IBM, Paypal, etc. para convertirse en un estándar de facto para las API.
En esta charla, contaremos con Pedro J. Molina (@pmolinam) como ponente, y veremos 3 casos de usos para aplicar OpenAPI para mejorar y acelerar nuestros desarrollos para crear APIs compatibles con OpenAPI:
- Legacy APIs,
- Contract first y,
- Server driven
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
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
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
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
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