SlideShare a Scribd company logo
Defining APIs using
Swagger
JOAQUIN COPETE
JCOPETEG@GMAIL.COM
What’s Swagger?
 Agnostic definition language used for REST APIs
 Machine and human readable
 Allows discover and understand a service capabilities without acceding
source code, formal documentation, …
 Swagger provides a toolbox ecosystem:
 User interface
 Code libraries
 Language editor
 Used by API Management solutions as Apigee, IBM, WSO2 among others.
jcopete.com
REST API basic definition
 Minimal mandatory elements needed to define a REST API, using Swagger,
are:
 Swagger: defines swagger version´s to be used, as last one is 2.0 we will use this
from now on.
 Info: API metadata information
 Title: API’s title or name
 Description: short API description
 Version: API version
 Paths: holds different resources and API operations
jcopete.com
REST API basic definition
jcopete.com
Defining response format
 Different data types to be produced or consumed can be specified by
using “definitions” object.
 So let´s define an “Error” data type with following properties:
 code: integer in int32 format
 message: a char string
 fields: a char string
 Let´s then define a “Product” data type with following properties:
 productId: a char string
 description: a char string
 name: a char string
 capacity: a char string
 Image: a char string
jcopete.com
Defining response format
jcopete.com
Defining API resources
 To define API resources specify a “path” object. Previously we defined a
minimum products “path”.
 Extend existing minimum products “path” with following attributes:
 Tags: not mandatory, but will help when searching.
 Summary: a brief definition for this operation.
 Description: a detailed description for this operation.
 operationId: a
 Extendemos el “path” mínimo con los siguientes atributos:
 tags: no es obligatorio, pero nos facilitará las búsquedas en el API.
 summary: un pequeño resumen de la función de esta operación.
 description: una descripción detallada de la operación.
 operationId: un nombre único, y amigable, de operación.
jcopete.com
Defining API responses
 Use “responses” object to define given responses for each resource
 responses: composed of several elements (description, schema, headers,
examples), for this sample we will just use two of them:
 description: response description. (Mandatory).
 schema: defines response structure. It can be a basic type, a primitive or another
object already defined in “definitions” section.
For our example response for “products” resource will be defined using the definition that is
already created under “definitions” section. We will use a common error definition for
different scenarios.
jcopete.com
Responses
jcopete.com
API parameters definition
 “Parameters” object defines request parameters; For the example will
assume that all parameters are transferred by using a query-string.
 Each parameter is defined in the following way:
 name: parameter’s name (mandatory)
 in: parameter type [ query, header, path, formData o body ]. (mandatory). We will use
query for this example.
 description: short parameter description.
 required: determines wether the parameter is mandatory. [ true, false ]
 We will use 2 additional elements:
 type: parameter type (mandatory if type is not body).
 tormat: data type format previously defined.
jcopete.com
Parameters
jcopete.com
Thanks
Joaquin copete
jcopeteg@gmail.com
jcopete.com

More Related Content

Viewers also liked

Into manchester presentation purple
Into manchester presentation purpleInto manchester presentation purple
Into manchester presentation purple
guestf17a36d
 
Taller 3 funciones quiero que me ayuden a resolverlo
Taller 3 funciones quiero que me ayuden a resolverlo Taller 3 funciones quiero que me ayuden a resolverlo
Taller 3 funciones quiero que me ayuden a resolverlo
Jeiner Paez
 

Viewers also liked (20)

API Design first with Swagger
API Design first with SwaggerAPI Design first with Swagger
API Design first with Swagger
 
Understanding how to use Swagger and its tools
Understanding how to use Swagger and its toolsUnderstanding how to use Swagger and its tools
Understanding how to use Swagger and its tools
 
Swagger / Quick Start Guide
Swagger / Quick Start GuideSwagger / Quick Start Guide
Swagger / Quick Start Guide
 
Spiders 6
Spiders  6Spiders  6
Spiders 6
 
La fórmula més estimada pel professor
La fórmula més estimada pel professorLa fórmula més estimada pel professor
La fórmula més estimada pel professor
 
07 Ene20
07 Ene2007 Ene20
07 Ene20
 
VmWare on IBM Cloud
VmWare on IBM Cloud VmWare on IBM Cloud
VmWare on IBM Cloud
 
Into manchester presentation purple
Into manchester presentation purpleInto manchester presentation purple
Into manchester presentation purple
 
Taller 3 funciones quiero que me ayuden a resolverlo
Taller 3 funciones quiero que me ayuden a resolverlo Taller 3 funciones quiero que me ayuden a resolverlo
Taller 3 funciones quiero que me ayuden a resolverlo
 
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
 
Introducing Swagger
Introducing SwaggerIntroducing Swagger
Introducing Swagger
 
GWP presentation
GWP presentationGWP presentation
GWP presentation
 
Google earth gaez tool
Google earth gaez toolGoogle earth gaez tool
Google earth gaez tool
 
Derivacion implicita
Derivacion implicitaDerivacion implicita
Derivacion implicita
 
Swagger - make your API accessible
Swagger - make your API accessibleSwagger - make your API accessible
Swagger - make your API accessible
 
Swagger demo
Swagger demoSwagger demo
Swagger demo
 
Role of higher ed institutions in the malawi nap
Role of higher ed institutions in the malawi napRole of higher ed institutions in the malawi nap
Role of higher ed institutions in the malawi nap
 
Swagger for-your-api
Swagger for-your-apiSwagger for-your-api
Swagger for-your-api
 
Swaggerを利用した新規サービス開発
Swaggerを利用した新規サービス開発Swaggerを利用した新規サービス開発
Swaggerを利用した新規サービス開発
 
Introduction to Swagger
Introduction to SwaggerIntroduction to Swagger
Introduction to Swagger
 

Similar to Build Swagger definition - Sample

Similar to Build Swagger definition - Sample (20)

Introducing swagger
Introducing swaggerIntroducing swagger
Introducing swagger
 
apidays LIVE New York - API Code First vs Design First by Phil Sturgeon
apidays LIVE New York - API Code First vs Design First by Phil Sturgeonapidays LIVE New York - API Code First vs Design First by Phil Sturgeon
apidays LIVE New York - API Code First vs Design First by Phil Sturgeon
 
Elefrant [ng-Poznan]
Elefrant [ng-Poznan]Elefrant [ng-Poznan]
Elefrant [ng-Poznan]
 
Make Your API Catalog Essential with z/OS Connect EE
Make Your API Catalog Essential with z/OS Connect EEMake Your API Catalog Essential with z/OS Connect EE
Make Your API Catalog Essential with z/OS Connect EE
 
Api Testing.pdf
Api Testing.pdfApi Testing.pdf
Api Testing.pdf
 
Schema-First API Design
Schema-First API DesignSchema-First API Design
Schema-First API Design
 
Play Your API with MuleSoft API Notebook
Play Your API with MuleSoft API NotebookPlay Your API with MuleSoft API Notebook
Play Your API with MuleSoft API Notebook
 
Itb 2021 - Bulding Quick APIs by Gavin Pickin
Itb 2021 - Bulding Quick APIs by Gavin PickinItb 2021 - Bulding Quick APIs by Gavin Pickin
Itb 2021 - Bulding Quick APIs by Gavin Pickin
 
Method and decorator
Method and decoratorMethod and decorator
Method and decorator
 
Java interview questions and answers
Java interview questions and answersJava interview questions and answers
Java interview questions and answers
 
IBM Integration Bus and REST APIs - Sanjay Nagchowdhury
IBM Integration Bus and REST APIs - Sanjay NagchowdhuryIBM Integration Bus and REST APIs - Sanjay Nagchowdhury
IBM Integration Bus and REST APIs - Sanjay Nagchowdhury
 
Operator SDK for K8s using Go
Operator SDK for K8s using GoOperator SDK for K8s using Go
Operator SDK for K8s using Go
 
SVQdotNET: Building APIs with OpenApi
SVQdotNET: Building APIs with OpenApiSVQdotNET: Building APIs with OpenApi
SVQdotNET: Building APIs with OpenApi
 
SpringBootCompleteBootcamp.pptx
SpringBootCompleteBootcamp.pptxSpringBootCompleteBootcamp.pptx
SpringBootCompleteBootcamp.pptx
 
OWASP PDX May 2016 : Scanning with Swagger (OAS) 2.0
OWASP PDX May 2016 : Scanning with Swagger (OAS) 2.0 OWASP PDX May 2016 : Scanning with Swagger (OAS) 2.0
OWASP PDX May 2016 : Scanning with Swagger (OAS) 2.0
 
Java J2EE Interview Question Part 2
Java J2EE Interview Question Part 2Java J2EE Interview Question Part 2
Java J2EE Interview Question Part 2
 
Java J2EE Interview Questions Part 2
Java J2EE Interview Questions Part 2Java J2EE Interview Questions Part 2
Java J2EE Interview Questions Part 2
 
Why UI Developers Love GraphQL - Sashko Stubailo, Apollo/Meteor
Why UI Developers Love GraphQL - Sashko Stubailo, Apollo/MeteorWhy UI Developers Love GraphQL - Sashko Stubailo, Apollo/Meteor
Why UI Developers Love GraphQL - Sashko Stubailo, Apollo/Meteor
 
Why UI developers love GraphQL
Why UI developers love GraphQLWhy UI developers love GraphQL
Why UI developers love GraphQL
 
Multi-dimensional exploration of API usage - ICPC13 - 21-05-13
Multi-dimensional exploration of API usage - ICPC13 - 21-05-13Multi-dimensional exploration of API usage - ICPC13 - 21-05-13
Multi-dimensional exploration of API usage - ICPC13 - 21-05-13
 

Recently uploaded

Article writing on excessive use of internet.pptx
Article writing on excessive use of internet.pptxArticle writing on excessive use of internet.pptx
Article writing on excessive use of internet.pptx
abhinandnam9997
 
一比一原版UTS毕业证悉尼科技大学毕业证成绩单如何办理
一比一原版UTS毕业证悉尼科技大学毕业证成绩单如何办理一比一原版UTS毕业证悉尼科技大学毕业证成绩单如何办理
一比一原版UTS毕业证悉尼科技大学毕业证成绩单如何办理
aagad
 

Recently uploaded (12)

The+Prospects+of+E-Commerce+in+China.pptx
The+Prospects+of+E-Commerce+in+China.pptxThe+Prospects+of+E-Commerce+in+China.pptx
The+Prospects+of+E-Commerce+in+China.pptx
 
The AI Powered Organization-Intro to AI-LAN.pdf
The AI Powered Organization-Intro to AI-LAN.pdfThe AI Powered Organization-Intro to AI-LAN.pdf
The AI Powered Organization-Intro to AI-LAN.pdf
 
ER(Entity Relationship) Diagram for online shopping - TAE
ER(Entity Relationship) Diagram for online shopping - TAEER(Entity Relationship) Diagram for online shopping - TAE
ER(Entity Relationship) Diagram for online shopping - TAE
 
Article writing on excessive use of internet.pptx
Article writing on excessive use of internet.pptxArticle writing on excessive use of internet.pptx
Article writing on excessive use of internet.pptx
 
How Do I Begin the Linksys Velop Setup Process?
How Do I Begin the Linksys Velop Setup Process?How Do I Begin the Linksys Velop Setup Process?
How Do I Begin the Linksys Velop Setup Process?
 
The Best AI Powered Software - Intellivid AI Studio
The Best AI Powered Software - Intellivid AI StudioThe Best AI Powered Software - Intellivid AI Studio
The Best AI Powered Software - Intellivid AI Studio
 
Pvtaan Social media marketing proposal.pdf
Pvtaan Social media marketing proposal.pdfPvtaan Social media marketing proposal.pdf
Pvtaan Social media marketing proposal.pdf
 
How to Use Contact Form 7 Like a Pro.pptx
How to Use Contact Form 7 Like a Pro.pptxHow to Use Contact Form 7 Like a Pro.pptx
How to Use Contact Form 7 Like a Pro.pptx
 
Multi-cluster Kubernetes Networking- Patterns, Projects and Guidelines
Multi-cluster Kubernetes Networking- Patterns, Projects and GuidelinesMulti-cluster Kubernetes Networking- Patterns, Projects and Guidelines
Multi-cluster Kubernetes Networking- Patterns, Projects and Guidelines
 
一比一原版UTS毕业证悉尼科技大学毕业证成绩单如何办理
一比一原版UTS毕业证悉尼科技大学毕业证成绩单如何办理一比一原版UTS毕业证悉尼科技大学毕业证成绩单如何办理
一比一原版UTS毕业证悉尼科技大学毕业证成绩单如何办理
 
The Use of AI in Indonesia Election 2024: A Case Study
The Use of AI in Indonesia Election 2024: A Case StudyThe Use of AI in Indonesia Election 2024: A Case Study
The Use of AI in Indonesia Election 2024: A Case Study
 
History+of+E-commerce+Development+in+China-www.cfye-commerce.shop
History+of+E-commerce+Development+in+China-www.cfye-commerce.shopHistory+of+E-commerce+Development+in+China-www.cfye-commerce.shop
History+of+E-commerce+Development+in+China-www.cfye-commerce.shop
 

Build Swagger definition - Sample

  • 1. Defining APIs using Swagger JOAQUIN COPETE JCOPETEG@GMAIL.COM
  • 2. What’s Swagger?  Agnostic definition language used for REST APIs  Machine and human readable  Allows discover and understand a service capabilities without acceding source code, formal documentation, …  Swagger provides a toolbox ecosystem:  User interface  Code libraries  Language editor  Used by API Management solutions as Apigee, IBM, WSO2 among others. jcopete.com
  • 3. REST API basic definition  Minimal mandatory elements needed to define a REST API, using Swagger, are:  Swagger: defines swagger version´s to be used, as last one is 2.0 we will use this from now on.  Info: API metadata information  Title: API’s title or name  Description: short API description  Version: API version  Paths: holds different resources and API operations jcopete.com
  • 4. REST API basic definition jcopete.com
  • 5. Defining response format  Different data types to be produced or consumed can be specified by using “definitions” object.  So let´s define an “Error” data type with following properties:  code: integer in int32 format  message: a char string  fields: a char string  Let´s then define a “Product” data type with following properties:  productId: a char string  description: a char string  name: a char string  capacity: a char string  Image: a char string jcopete.com
  • 7. Defining API resources  To define API resources specify a “path” object. Previously we defined a minimum products “path”.  Extend existing minimum products “path” with following attributes:  Tags: not mandatory, but will help when searching.  Summary: a brief definition for this operation.  Description: a detailed description for this operation.  operationId: a  Extendemos el “path” mínimo con los siguientes atributos:  tags: no es obligatorio, pero nos facilitará las búsquedas en el API.  summary: un pequeño resumen de la función de esta operación.  description: una descripción detallada de la operación.  operationId: un nombre único, y amigable, de operación. jcopete.com
  • 8. Defining API responses  Use “responses” object to define given responses for each resource  responses: composed of several elements (description, schema, headers, examples), for this sample we will just use two of them:  description: response description. (Mandatory).  schema: defines response structure. It can be a basic type, a primitive or another object already defined in “definitions” section. For our example response for “products” resource will be defined using the definition that is already created under “definitions” section. We will use a common error definition for different scenarios. jcopete.com
  • 10. API parameters definition  “Parameters” object defines request parameters; For the example will assume that all parameters are transferred by using a query-string.  Each parameter is defined in the following way:  name: parameter’s name (mandatory)  in: parameter type [ query, header, path, formData o body ]. (mandatory). We will use query for this example.  description: short parameter description.  required: determines wether the parameter is mandatory. [ true, false ]  We will use 2 additional elements:  type: parameter type (mandatory if type is not body).  tormat: data type format previously defined. jcopete.com