SlideShare a Scribd company logo
Swagger
Implement Web API documents
Jiang Wu
2015-09-12
Jiang Wu Swagger 2015-09-12 1 / 42
Context
1 Introduction
2 Swagger
3 PostgREST
4 Summary
Jiang Wu Swagger 2015-09-12 2 / 42
Do you remember this?
Jiang Wu Swagger 2015-09-12 3 / 42
本尊在此 It’s me!
Jiang Wu Swagger 2015-09-12 4 / 42
Scenario 場景
Why we adopted Swagger?
Rails application
3 types of API consumers
▶ Native application
(iOS/Android/PC/Mac)
▶ Third party service
▶ Javascript: single page application
Jiang Wu Swagger 2015-09-12 5 / 42
Constraints 約束
HTTP/1.1
JSON data format
REST architecture style
Jiang Wu Swagger 2015-09-12 6 / 42
Ruby Gems
grape REST services
doorkeeper OAuth provider
Thanks yorkxin’s blog for the help.
Jiang Wu Swagger 2015-09-12 7 / 42
API documentations
Must be important, clear and accurate.
重要 跨專案組,跨公司
清楚 減少交流成本
正確 和程式碼保持同步
Jiang Wu Swagger 2015-09-12 8 / 42
程式設計師痛恨兩件事情
寫⽂檔
別⼈不寫⽂檔
Coders hate 2 things: writing
documentation and no documentation.
Solution
’D’o not ’R’epeat ’Y’ourself Priciple
Jiang Wu Swagger 2015-09-12 9 / 42
Remove duplication
documentation -> code WSDL
code -> documentation RDoc, YARD,
Rocco(annotated source code)
literate programming noweb, Org Mode,
Literate Haskell
Jiang Wu Swagger 2015-09-12 10 / 42
Context
1 Introduction
2 Swagger
3 PostgREST
4 Summary
Jiang Wu Swagger 2015-09-12 11 / 42
Demo
https://api.gitcafe.com/apidoc/
Jiang Wu Swagger 2015-09-12 12 / 42
Definitions
Swagger
Describe REST services
Swagger UI
Live testable documentation
grape-swagger
Generate API description
Jiang Wu Swagger 2015-09-12 13 / 42
Describe REST services
API routes
Input types
Output types
Authorizations
Jiang Wu Swagger 2015-09-12 14 / 42
Implementation 實作
1 Grape basic declaration
2 Namespace and routes
3 ’params’ -> input type
4 Grape::Entity -> output type
5 Doorkeeper -> OAuth authorizations
6 Swagger information
Jiang Wu Swagger 2015-09-12 15 / 42
Grape basic declaration
class API < Grape::API
# API routes prefix
prefix 'api'
# API version
version 'v1', using: :path
# load other API
mount Endpoints
end
Jiang Wu Swagger 2015-09-12 16 / 42
namespaces 命名空間
namespace "projects" do
mount ProjectsAPI
# namepsaces can be variable
# and cascadable
namespace ":identity" do
mount SingleProjectAPI
end
end
Jiang Wu Swagger 2015-09-12 17 / 42
API routes
Sinatra like DSL, declared with HTTP
methods.
desc "Show single project"
# get|post|put|patch|delete
get "/:project" do
# Your implementation
end
Jiang Wu Swagger 2015-09-12 18 / 42
Input types 輸⼊類型
params do
requires :name, type: String
optional :public,
type: Boolean,
default: false
end
Validate requests and return 400 status
code for typecast error or missing value.
Jiang Wu Swagger 2015-09-12 19 / 42
Output types 輸出類型
class Project < Grape::Entity
# Output fields
expose :name,
documentation: {
type: 'string',
desc: 'Project name'
}
end
Jiang Wu Swagger 2015-09-12 20 / 42
Refer to other types
class Project < Grape::Entity
expose :owner,
# with 'using'
using: Account,
documentation: {
type: 'Account'
}
end
Jiang Wu Swagger 2015-09-12 21 / 42
OAuth authorizations
Rails + doorkeeper
OAuth admin page
OAuth grant flow
Grape + doorkeeper
Handle OAuth token
Jiang Wu Swagger 2015-09-12 22 / 42
Swagger information (1)
Delare with
add_swagger_documentation
api_version
mount_path
authorizations
info
Jiang Wu Swagger 2015-09-12 23 / 42
Swagger informations (2)
Add documentaions of
namespace
params
output types (options of ’desc’)
OAuth scopes (options of ’desc’)
API codes (options of ’get’/’post’)
Jiang Wu Swagger 2015-09-12 24 / 42
Live Test
Similiar as doctest of Python
""" input and output, REPL way
>>> factorial(5)
120
"""
def factorial(n):
Documentation is both sample and test.
Jiang Wu Swagger 2015-09-12 25 / 42
API test before Swagger
Write it by yourself
Browser plugins (not quite works)
RestClient Firefox + Chrome
Proprietary softwares
Postman Chrome + NodeJS
Paw Mac
Jiang Wu Swagger 2015-09-12 26 / 42
Short summary of Swagger
API routes
Input types
Output types
Authorizations
Jiang Wu Swagger 2015-09-12 27 / 42
Ruby Swagger clients
REST clients are not Swagger specific
I started my work 3 days ago
Will be available soon
Virtus gem for type check
Meta programming DSL
Jiang Wu Swagger 2015-09-12 28 / 42
Unleash power of database
API Database
Routes Tables/Views
Input types Constraints, Types
Output types Table columns
Authorizations Roles
Jiang Wu Swagger 2015-09-12 29 / 42
Context
1 Introduction
2 Swagger
3 PostgREST
4 Summary
Jiang Wu Swagger 2015-09-12 30 / 42
Design philisophy
Can we use the declarative
information in a relational db
schema to mechanically generate
an HTTP API?
begriffs
Jiang Wu Swagger 2015-09-12 31 / 42
Features of PostgreSQL
Data types Array, HStore, GIS,
JSONB(since 9.4)
Procedure languages PL/pgSQL,
PL/Python, PL/V8
Message queue NOTIFY/LISTEN
Full text search tsvector/tsquery
Jiang Wu Swagger 2015-09-12 32 / 42
Schema -> API
Schema path -> API version
Tables/views -> API routes
Where clause -> query params
GET
/projects?age=lt.P7D&public=eq.true
Query projects created in 7 days and
public.
Jiang Wu Swagger 2015-09-12 33 / 42
Pagination -> Range headers
GET /items HTTP/1.1
Range-Unit: items
Range: 0-24
HTTP/1.1 206 Partial Content
Accept-Ranges: items
Content-Range: 0-24/100
Range-Unit: items
Jiang Wu Swagger 2015-09-12 34 / 42
DML -> HTTP methods
insert POST
update PATCH
upsert/merge PUT
delete DELETE
Jiang Wu Swagger 2015-09-12 35 / 42
DB Roles -> Authorizations
Need extra works to support normal
database-based authentication and
authorizations.
Jiang Wu Swagger 2015-09-12 36 / 42
Why PostgREST?
Counter attack to NoSQL
Bare metal speed (written in Haskell)
HTTP protocol
Jiang Wu Swagger 2015-09-12 37 / 42
Context
1 Introduction
2 Swagger
3 PostgREST
4 Summary
Jiang Wu Swagger 2015-09-12 38 / 42
Swagger
Describe REST services
Provide Live testable documentation
with Swagger UI
Can generate with grape-swagger
Disadvantage: have to investigate
across components when debugging
Ruby client: under work
Jiang Wu Swagger 2015-09-12 39 / 42
PostgREST
DB Schema -> API
Rediscover values of RDBMS
Advantage: can utilize more mature
tools built around RDBMS
Jiang Wu Swagger 2015-09-12 40 / 42
Apply DRY principle
Abstract not duplicate
Select proper tools
Bring values
Jiang Wu Swagger 2015-09-12 41 / 42
Q&A
Questions?
Twitter: @masterwujiang
Github: @nouse
Linkedin: @nouse
Jiang Wu Swagger 2015-09-12 42 / 42

More Related Content

What's hot

Consuming Restful APIs using Swagger v2.0
Consuming Restful APIs using Swagger v2.0Consuming Restful APIs using Swagger v2.0
Consuming Restful APIs using Swagger v2.0
Pece Nikolovski
 
Quick run in with Swagger
Quick run in with SwaggerQuick run in with Swagger
Quick run in with Swagger
Mesh Korea
 
Design Driven API Development
Design Driven API DevelopmentDesign Driven API Development
Design Driven API Development
Sokichi Fujita
 
Streamlining API with Swagger.io
Streamlining API with Swagger.ioStreamlining API with Swagger.io
Streamlining API with Swagger.io
Victor Augusteo
 
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 API
 
A Tour of Swagger for APIs
A Tour of Swagger for APIsA Tour of Swagger for APIs
A Tour of Swagger for APIs
Allen Dean
 
Introducing Swagger
Introducing SwaggerIntroducing Swagger
Introducing Swagger
Tony Tam
 
Introducing swagger
Introducing swaggerIntroducing swagger
Introducing swagger
Amr Ali
 
Developing Faster with Swagger
Developing Faster with SwaggerDeveloping Faster with Swagger
Developing Faster with Swagger
Tony Tam
 
Writer APIs in Java faster with Swagger Inflector
Writer APIs in Java faster with Swagger InflectorWriter APIs in Java faster with Swagger Inflector
Writer APIs in Java faster with Swagger Inflector
Tony Tam
 
Level 3 REST Makes Your API Browsable
Level 3 REST Makes Your API BrowsableLevel 3 REST Makes Your API Browsable
Level 3 REST Makes Your API Browsable
Matt Bishop
 
What is Swagger?
What is Swagger?What is Swagger?
What is Swagger?
Philip Senger
 
Swagger
SwaggerSwagger
Swagger 2.0 and Model-driven APIs
Swagger 2.0 and Model-driven APIsSwagger 2.0 and Model-driven APIs
Swagger 2.0 and Model-driven APIs
Apigee | Google Cloud
 
Designing APIs with OpenAPI Spec
Designing APIs with OpenAPI SpecDesigning APIs with OpenAPI Spec
Designing APIs with OpenAPI Spec
Adam Paxton
 
Swagger 2.0: Latest and Greatest
Swagger 2.0: Latest and GreatestSwagger 2.0: Latest and Greatest
Swagger 2.0: Latest and Greatest
LaunchAny
 
Document your rest api using swagger - Devoxx 2015
Document your rest api using swagger - Devoxx 2015Document your rest api using swagger - Devoxx 2015
Document your rest api using swagger - Devoxx 2015
johannes_fiala
 
Crystal clear service interfaces w/ Swagger/OpenAPI
Crystal clear service interfaces w/ Swagger/OpenAPICrystal clear service interfaces w/ Swagger/OpenAPI
Crystal clear service interfaces w/ Swagger/OpenAPI
Scott Triglia
 
API Developer Experience: Why it Matters, and How Documenting Your API with S...
API Developer Experience: Why it Matters, and How Documenting Your API with S...API Developer Experience: Why it Matters, and How Documenting Your API with S...
API Developer Experience: Why it Matters, and How Documenting Your API with S...
SmartBear
 
Swagger / Quick Start Guide
Swagger / Quick Start GuideSwagger / Quick Start Guide
Swagger / Quick Start Guide
Andrii Gakhov
 

What's hot (20)

Consuming Restful APIs using Swagger v2.0
Consuming Restful APIs using Swagger v2.0Consuming Restful APIs using Swagger v2.0
Consuming Restful APIs using Swagger v2.0
 
Quick run in with Swagger
Quick run in with SwaggerQuick run in with Swagger
Quick run in with Swagger
 
Design Driven API Development
Design Driven API DevelopmentDesign Driven API Development
Design Driven API Development
 
Streamlining API with Swagger.io
Streamlining API with Swagger.ioStreamlining API with Swagger.io
Streamlining API with Swagger.io
 
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
 
A Tour of Swagger for APIs
A Tour of Swagger for APIsA Tour of Swagger for APIs
A Tour of Swagger for APIs
 
Introducing Swagger
Introducing SwaggerIntroducing Swagger
Introducing Swagger
 
Introducing swagger
Introducing swaggerIntroducing swagger
Introducing swagger
 
Developing Faster with Swagger
Developing Faster with SwaggerDeveloping Faster with Swagger
Developing Faster with Swagger
 
Writer APIs in Java faster with Swagger Inflector
Writer APIs in Java faster with Swagger InflectorWriter APIs in Java faster with Swagger Inflector
Writer APIs in Java faster with Swagger Inflector
 
Level 3 REST Makes Your API Browsable
Level 3 REST Makes Your API BrowsableLevel 3 REST Makes Your API Browsable
Level 3 REST Makes Your API Browsable
 
What is Swagger?
What is Swagger?What is Swagger?
What is Swagger?
 
Swagger
SwaggerSwagger
Swagger
 
Swagger 2.0 and Model-driven APIs
Swagger 2.0 and Model-driven APIsSwagger 2.0 and Model-driven APIs
Swagger 2.0 and Model-driven APIs
 
Designing APIs with OpenAPI Spec
Designing APIs with OpenAPI SpecDesigning APIs with OpenAPI Spec
Designing APIs with OpenAPI Spec
 
Swagger 2.0: Latest and Greatest
Swagger 2.0: Latest and GreatestSwagger 2.0: Latest and Greatest
Swagger 2.0: Latest and Greatest
 
Document your rest api using swagger - Devoxx 2015
Document your rest api using swagger - Devoxx 2015Document your rest api using swagger - Devoxx 2015
Document your rest api using swagger - Devoxx 2015
 
Crystal clear service interfaces w/ Swagger/OpenAPI
Crystal clear service interfaces w/ Swagger/OpenAPICrystal clear service interfaces w/ Swagger/OpenAPI
Crystal clear service interfaces w/ Swagger/OpenAPI
 
API Developer Experience: Why it Matters, and How Documenting Your API with S...
API Developer Experience: Why it Matters, and How Documenting Your API with S...API Developer Experience: Why it Matters, and How Documenting Your API with S...
API Developer Experience: Why it Matters, and How Documenting Your API with S...
 
Swagger / Quick Start Guide
Swagger / Quick Start GuideSwagger / Quick Start Guide
Swagger / Quick Start Guide
 

Similar to Implement Web API with Swagger

GraphQL - A query language to empower your API consumers (NDC Sydney 2017)
GraphQL - A query language to empower your API consumers (NDC Sydney 2017)GraphQL - A query language to empower your API consumers (NDC Sydney 2017)
GraphQL - A query language to empower your API consumers (NDC Sydney 2017)
Rob Crowley
 
Get Hip with JHipster - GIDS 2019
Get Hip with JHipster - GIDS 2019Get Hip with JHipster - GIDS 2019
Get Hip with JHipster - GIDS 2019
Matt Raible
 
Cowboy dating with big data TechDays at Lohika-2020
Cowboy dating with big data TechDays at Lohika-2020Cowboy dating with big data TechDays at Lohika-2020
Cowboy dating with big data TechDays at Lohika-2020
b0ris_1
 
Getting Started with WebSocket and Server-Sent Events using Java - Arun Gupta...
Getting Started with WebSocket and Server-Sent Events using Java - Arun Gupta...Getting Started with WebSocket and Server-Sent Events using Java - Arun Gupta...
Getting Started with WebSocket and Server-Sent Events using Java - Arun Gupta...
jaxLondonConference
 
Getting Started with WebSockets and Server-Sent Events
Getting Started with WebSockets and Server-Sent EventsGetting Started with WebSockets and Server-Sent Events
Getting Started with WebSockets and Server-Sent EventsArun Gupta
 
Seattle StrongLoop Node.js Workshop
Seattle StrongLoop Node.js WorkshopSeattle StrongLoop Node.js Workshop
Seattle StrongLoop Node.js Workshop
Jimmy Guerrero
 
Timings API: Performance Assertion during the functional testing
 Timings API: Performance Assertion during the functional testing Timings API: Performance Assertion during the functional testing
Timings API: Performance Assertion during the functional testing
PetrosPlakogiannis
 
OGCE Project Overview
OGCE Project OverviewOGCE Project Overview
OGCE Project Overview
marpierc
 
OGCE Overview for SciDAC 2009
OGCE Overview for SciDAC 2009OGCE Overview for SciDAC 2009
OGCE Overview for SciDAC 2009marpierc
 
Ibm_interconnect_restapi_workshop
Ibm_interconnect_restapi_workshopIbm_interconnect_restapi_workshop
Ibm_interconnect_restapi_workshop
Shubhra Kar
 
REST to JavaScript for Better Client-side Development
REST to JavaScript for Better Client-side DevelopmentREST to JavaScript for Better Client-side Development
REST to JavaScript for Better Client-side Development
Hyunghun Cho
 
APIdays Paris 2019 - API Descriptions as Product Code by Phil Sturgeon, Stopl...
APIdays Paris 2019 - API Descriptions as Product Code by Phil Sturgeon, Stopl...APIdays Paris 2019 - API Descriptions as Product Code by Phil Sturgeon, Stopl...
APIdays Paris 2019 - API Descriptions as Product Code by Phil Sturgeon, Stopl...
apidays
 
AngularJS with TypeScript and Windows Azure Mobile Services
AngularJS with TypeScript and Windows Azure Mobile ServicesAngularJS with TypeScript and Windows Azure Mobile Services
AngularJS with TypeScript and Windows Azure Mobile Services
Rainer Stropek
 
CQ5 and Sling overview
CQ5 and Sling overviewCQ5 and Sling overview
CQ5 and Sling overview
Bertrand Delacretaz
 
PPT for Seminar.pptx
PPT for Seminar.pptxPPT for Seminar.pptx
PPT for Seminar.pptx
Akshay Bhujbal
 
Exposing GraphQLs as Managed APIs
Exposing GraphQLs as Managed APIsExposing GraphQLs as Managed APIs
Exposing GraphQLs as Managed APIs
WSO2
 
Headless Drupal en pratique
Headless Drupal en pratiqueHeadless Drupal en pratique
Headless Drupal en pratique
Simon Morvan
 
Rapid Application Development with WSO2 Platform
Rapid Application Development with WSO2 PlatformRapid Application Development with WSO2 Platform
Rapid Application Development with WSO2 PlatformWSO2
 
Red Hat Agile integration workshop - Atlanta
Red Hat Agile integration workshop - AtlantaRed Hat Agile integration workshop - Atlanta
Red Hat Agile integration workshop - Atlanta
Judy Breedlove
 

Similar to Implement Web API with Swagger (20)

GraphQL - A query language to empower your API consumers (NDC Sydney 2017)
GraphQL - A query language to empower your API consumers (NDC Sydney 2017)GraphQL - A query language to empower your API consumers (NDC Sydney 2017)
GraphQL - A query language to empower your API consumers (NDC Sydney 2017)
 
Get Hip with JHipster - GIDS 2019
Get Hip with JHipster - GIDS 2019Get Hip with JHipster - GIDS 2019
Get Hip with JHipster - GIDS 2019
 
Cowboy dating with big data TechDays at Lohika-2020
Cowboy dating with big data TechDays at Lohika-2020Cowboy dating with big data TechDays at Lohika-2020
Cowboy dating with big data TechDays at Lohika-2020
 
Getting Started with WebSocket and Server-Sent Events using Java - Arun Gupta...
Getting Started with WebSocket and Server-Sent Events using Java - Arun Gupta...Getting Started with WebSocket and Server-Sent Events using Java - Arun Gupta...
Getting Started with WebSocket and Server-Sent Events using Java - Arun Gupta...
 
Getting Started with WebSockets and Server-Sent Events
Getting Started with WebSockets and Server-Sent EventsGetting Started with WebSockets and Server-Sent Events
Getting Started with WebSockets and Server-Sent Events
 
Seattle StrongLoop Node.js Workshop
Seattle StrongLoop Node.js WorkshopSeattle StrongLoop Node.js Workshop
Seattle StrongLoop Node.js Workshop
 
Timings API: Performance Assertion during the functional testing
 Timings API: Performance Assertion during the functional testing Timings API: Performance Assertion during the functional testing
Timings API: Performance Assertion during the functional testing
 
OGCE Project Overview
OGCE Project OverviewOGCE Project Overview
OGCE Project Overview
 
Soap Toolkit Dcphp
Soap Toolkit DcphpSoap Toolkit Dcphp
Soap Toolkit Dcphp
 
OGCE Overview for SciDAC 2009
OGCE Overview for SciDAC 2009OGCE Overview for SciDAC 2009
OGCE Overview for SciDAC 2009
 
Ibm_interconnect_restapi_workshop
Ibm_interconnect_restapi_workshopIbm_interconnect_restapi_workshop
Ibm_interconnect_restapi_workshop
 
REST to JavaScript for Better Client-side Development
REST to JavaScript for Better Client-side DevelopmentREST to JavaScript for Better Client-side Development
REST to JavaScript for Better Client-side Development
 
APIdays Paris 2019 - API Descriptions as Product Code by Phil Sturgeon, Stopl...
APIdays Paris 2019 - API Descriptions as Product Code by Phil Sturgeon, Stopl...APIdays Paris 2019 - API Descriptions as Product Code by Phil Sturgeon, Stopl...
APIdays Paris 2019 - API Descriptions as Product Code by Phil Sturgeon, Stopl...
 
AngularJS with TypeScript and Windows Azure Mobile Services
AngularJS with TypeScript and Windows Azure Mobile ServicesAngularJS with TypeScript and Windows Azure Mobile Services
AngularJS with TypeScript and Windows Azure Mobile Services
 
CQ5 and Sling overview
CQ5 and Sling overviewCQ5 and Sling overview
CQ5 and Sling overview
 
PPT for Seminar.pptx
PPT for Seminar.pptxPPT for Seminar.pptx
PPT for Seminar.pptx
 
Exposing GraphQLs as Managed APIs
Exposing GraphQLs as Managed APIsExposing GraphQLs as Managed APIs
Exposing GraphQLs as Managed APIs
 
Headless Drupal en pratique
Headless Drupal en pratiqueHeadless Drupal en pratique
Headless Drupal en pratique
 
Rapid Application Development with WSO2 Platform
Rapid Application Development with WSO2 PlatformRapid Application Development with WSO2 Platform
Rapid Application Development with WSO2 Platform
 
Red Hat Agile integration workshop - Atlanta
Red Hat Agile integration workshop - AtlantaRed Hat Agile integration workshop - Atlanta
Red Hat Agile integration workshop - Atlanta
 

More from Jiang Wu

Python speed up with numba
Python speed up with numbaPython speed up with numba
Python speed up with numba
Jiang Wu
 
用Ruby编写博客应用
用Ruby编写博客应用用Ruby编写博客应用
用Ruby编写博客应用
Jiang Wu
 
Sinatra and friends
Sinatra and friendsSinatra and friends
Sinatra and friends
Jiang Wu
 
Rubyconf China
Rubyconf ChinaRubyconf China
Rubyconf China
Jiang Wu
 
JS2
JS2JS2
Ruby off Rails---rack, sinatra and sequel
Ruby off Rails---rack, sinatra and sequelRuby off Rails---rack, sinatra and sequel
Ruby off Rails---rack, sinatra and sequel
Jiang Wu
 

More from Jiang Wu (6)

Python speed up with numba
Python speed up with numbaPython speed up with numba
Python speed up with numba
 
用Ruby编写博客应用
用Ruby编写博客应用用Ruby编写博客应用
用Ruby编写博客应用
 
Sinatra and friends
Sinatra and friendsSinatra and friends
Sinatra and friends
 
Rubyconf China
Rubyconf ChinaRubyconf China
Rubyconf China
 
JS2
JS2JS2
JS2
 
Ruby off Rails---rack, sinatra and sequel
Ruby off Rails---rack, sinatra and sequelRuby off Rails---rack, sinatra and sequel
Ruby off Rails---rack, sinatra and sequel
 

Recently uploaded

How to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good PracticesHow to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good Practices
Globus
 
top nidhi software solution freedownload
top nidhi software solution freedownloadtop nidhi software solution freedownload
top nidhi software solution freedownload
vrstrong314
 
Cyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdfCyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdf
Cyanic lab
 
Lecture 1 Introduction to games development
Lecture 1 Introduction to games developmentLecture 1 Introduction to games development
Lecture 1 Introduction to games development
abdulrafaychaudhry
 
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2
 
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data AnalysisProviding Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
Globus
 
Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus
 
Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...
Globus
 
BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024
Ortus Solutions, Corp
 
Multiple Your Crypto Portfolio with the Innovative Features of Advanced Crypt...
Multiple Your Crypto Portfolio with the Innovative Features of Advanced Crypt...Multiple Your Crypto Portfolio with the Innovative Features of Advanced Crypt...
Multiple Your Crypto Portfolio with the Innovative Features of Advanced Crypt...
Hivelance Technology
 
Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024
Globus
 
Vitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume MontevideoVitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume Montevideo
Vitthal Shirke
 
Explore Modern SharePoint Templates for 2024
Explore Modern SharePoint Templates for 2024Explore Modern SharePoint Templates for 2024
Explore Modern SharePoint Templates for 2024
Sharepoint Designs
 
Why React Native as a Strategic Advantage for Startup Innovation.pdf
Why React Native as a Strategic Advantage for Startup Innovation.pdfWhy React Native as a Strategic Advantage for Startup Innovation.pdf
Why React Native as a Strategic Advantage for Startup Innovation.pdf
ayushiqss
 
Corporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMSCorporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMS
Tendenci - The Open Source AMS (Association Management Software)
 
Accelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with PlatformlessAccelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with Platformless
WSO2
 
First Steps with Globus Compute Multi-User Endpoints
First Steps with Globus Compute Multi-User EndpointsFirst Steps with Globus Compute Multi-User Endpoints
First Steps with Globus Compute Multi-User Endpoints
Globus
 
How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?
How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?
How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?
XfilesPro
 
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Anthony Dahanne
 
Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024
Globus
 

Recently uploaded (20)

How to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good PracticesHow to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good Practices
 
top nidhi software solution freedownload
top nidhi software solution freedownloadtop nidhi software solution freedownload
top nidhi software solution freedownload
 
Cyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdfCyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdf
 
Lecture 1 Introduction to games development
Lecture 1 Introduction to games developmentLecture 1 Introduction to games development
Lecture 1 Introduction to games development
 
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
 
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data AnalysisProviding Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
 
Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024
 
Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...
 
BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024
 
Multiple Your Crypto Portfolio with the Innovative Features of Advanced Crypt...
Multiple Your Crypto Portfolio with the Innovative Features of Advanced Crypt...Multiple Your Crypto Portfolio with the Innovative Features of Advanced Crypt...
Multiple Your Crypto Portfolio with the Innovative Features of Advanced Crypt...
 
Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024
 
Vitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume MontevideoVitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume Montevideo
 
Explore Modern SharePoint Templates for 2024
Explore Modern SharePoint Templates for 2024Explore Modern SharePoint Templates for 2024
Explore Modern SharePoint Templates for 2024
 
Why React Native as a Strategic Advantage for Startup Innovation.pdf
Why React Native as a Strategic Advantage for Startup Innovation.pdfWhy React Native as a Strategic Advantage for Startup Innovation.pdf
Why React Native as a Strategic Advantage for Startup Innovation.pdf
 
Corporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMSCorporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMS
 
Accelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with PlatformlessAccelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with Platformless
 
First Steps with Globus Compute Multi-User Endpoints
First Steps with Globus Compute Multi-User EndpointsFirst Steps with Globus Compute Multi-User Endpoints
First Steps with Globus Compute Multi-User Endpoints
 
How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?
How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?
How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?
 
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
 
Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024
 

Implement Web API with Swagger

  • 1. Swagger Implement Web API documents Jiang Wu 2015-09-12 Jiang Wu Swagger 2015-09-12 1 / 42
  • 2. Context 1 Introduction 2 Swagger 3 PostgREST 4 Summary Jiang Wu Swagger 2015-09-12 2 / 42
  • 3. Do you remember this? Jiang Wu Swagger 2015-09-12 3 / 42
  • 4. 本尊在此 It’s me! Jiang Wu Swagger 2015-09-12 4 / 42
  • 5. Scenario 場景 Why we adopted Swagger? Rails application 3 types of API consumers ▶ Native application (iOS/Android/PC/Mac) ▶ Third party service ▶ Javascript: single page application Jiang Wu Swagger 2015-09-12 5 / 42
  • 6. Constraints 約束 HTTP/1.1 JSON data format REST architecture style Jiang Wu Swagger 2015-09-12 6 / 42
  • 7. Ruby Gems grape REST services doorkeeper OAuth provider Thanks yorkxin’s blog for the help. Jiang Wu Swagger 2015-09-12 7 / 42
  • 8. API documentations Must be important, clear and accurate. 重要 跨專案組,跨公司 清楚 減少交流成本 正確 和程式碼保持同步 Jiang Wu Swagger 2015-09-12 8 / 42
  • 9. 程式設計師痛恨兩件事情 寫⽂檔 別⼈不寫⽂檔 Coders hate 2 things: writing documentation and no documentation. Solution ’D’o not ’R’epeat ’Y’ourself Priciple Jiang Wu Swagger 2015-09-12 9 / 42
  • 10. Remove duplication documentation -> code WSDL code -> documentation RDoc, YARD, Rocco(annotated source code) literate programming noweb, Org Mode, Literate Haskell Jiang Wu Swagger 2015-09-12 10 / 42
  • 11. Context 1 Introduction 2 Swagger 3 PostgREST 4 Summary Jiang Wu Swagger 2015-09-12 11 / 42
  • 13. Definitions Swagger Describe REST services Swagger UI Live testable documentation grape-swagger Generate API description Jiang Wu Swagger 2015-09-12 13 / 42
  • 14. Describe REST services API routes Input types Output types Authorizations Jiang Wu Swagger 2015-09-12 14 / 42
  • 15. Implementation 實作 1 Grape basic declaration 2 Namespace and routes 3 ’params’ -> input type 4 Grape::Entity -> output type 5 Doorkeeper -> OAuth authorizations 6 Swagger information Jiang Wu Swagger 2015-09-12 15 / 42
  • 16. Grape basic declaration class API < Grape::API # API routes prefix prefix 'api' # API version version 'v1', using: :path # load other API mount Endpoints end Jiang Wu Swagger 2015-09-12 16 / 42
  • 17. namespaces 命名空間 namespace "projects" do mount ProjectsAPI # namepsaces can be variable # and cascadable namespace ":identity" do mount SingleProjectAPI end end Jiang Wu Swagger 2015-09-12 17 / 42
  • 18. API routes Sinatra like DSL, declared with HTTP methods. desc "Show single project" # get|post|put|patch|delete get "/:project" do # Your implementation end Jiang Wu Swagger 2015-09-12 18 / 42
  • 19. Input types 輸⼊類型 params do requires :name, type: String optional :public, type: Boolean, default: false end Validate requests and return 400 status code for typecast error or missing value. Jiang Wu Swagger 2015-09-12 19 / 42
  • 20. Output types 輸出類型 class Project < Grape::Entity # Output fields expose :name, documentation: { type: 'string', desc: 'Project name' } end Jiang Wu Swagger 2015-09-12 20 / 42
  • 21. Refer to other types class Project < Grape::Entity expose :owner, # with 'using' using: Account, documentation: { type: 'Account' } end Jiang Wu Swagger 2015-09-12 21 / 42
  • 22. OAuth authorizations Rails + doorkeeper OAuth admin page OAuth grant flow Grape + doorkeeper Handle OAuth token Jiang Wu Swagger 2015-09-12 22 / 42
  • 23. Swagger information (1) Delare with add_swagger_documentation api_version mount_path authorizations info Jiang Wu Swagger 2015-09-12 23 / 42
  • 24. Swagger informations (2) Add documentaions of namespace params output types (options of ’desc’) OAuth scopes (options of ’desc’) API codes (options of ’get’/’post’) Jiang Wu Swagger 2015-09-12 24 / 42
  • 25. Live Test Similiar as doctest of Python """ input and output, REPL way >>> factorial(5) 120 """ def factorial(n): Documentation is both sample and test. Jiang Wu Swagger 2015-09-12 25 / 42
  • 26. API test before Swagger Write it by yourself Browser plugins (not quite works) RestClient Firefox + Chrome Proprietary softwares Postman Chrome + NodeJS Paw Mac Jiang Wu Swagger 2015-09-12 26 / 42
  • 27. Short summary of Swagger API routes Input types Output types Authorizations Jiang Wu Swagger 2015-09-12 27 / 42
  • 28. Ruby Swagger clients REST clients are not Swagger specific I started my work 3 days ago Will be available soon Virtus gem for type check Meta programming DSL Jiang Wu Swagger 2015-09-12 28 / 42
  • 29. Unleash power of database API Database Routes Tables/Views Input types Constraints, Types Output types Table columns Authorizations Roles Jiang Wu Swagger 2015-09-12 29 / 42
  • 30. Context 1 Introduction 2 Swagger 3 PostgREST 4 Summary Jiang Wu Swagger 2015-09-12 30 / 42
  • 31. Design philisophy Can we use the declarative information in a relational db schema to mechanically generate an HTTP API? begriffs Jiang Wu Swagger 2015-09-12 31 / 42
  • 32. Features of PostgreSQL Data types Array, HStore, GIS, JSONB(since 9.4) Procedure languages PL/pgSQL, PL/Python, PL/V8 Message queue NOTIFY/LISTEN Full text search tsvector/tsquery Jiang Wu Swagger 2015-09-12 32 / 42
  • 33. Schema -> API Schema path -> API version Tables/views -> API routes Where clause -> query params GET /projects?age=lt.P7D&public=eq.true Query projects created in 7 days and public. Jiang Wu Swagger 2015-09-12 33 / 42
  • 34. Pagination -> Range headers GET /items HTTP/1.1 Range-Unit: items Range: 0-24 HTTP/1.1 206 Partial Content Accept-Ranges: items Content-Range: 0-24/100 Range-Unit: items Jiang Wu Swagger 2015-09-12 34 / 42
  • 35. DML -> HTTP methods insert POST update PATCH upsert/merge PUT delete DELETE Jiang Wu Swagger 2015-09-12 35 / 42
  • 36. DB Roles -> Authorizations Need extra works to support normal database-based authentication and authorizations. Jiang Wu Swagger 2015-09-12 36 / 42
  • 37. Why PostgREST? Counter attack to NoSQL Bare metal speed (written in Haskell) HTTP protocol Jiang Wu Swagger 2015-09-12 37 / 42
  • 38. Context 1 Introduction 2 Swagger 3 PostgREST 4 Summary Jiang Wu Swagger 2015-09-12 38 / 42
  • 39. Swagger Describe REST services Provide Live testable documentation with Swagger UI Can generate with grape-swagger Disadvantage: have to investigate across components when debugging Ruby client: under work Jiang Wu Swagger 2015-09-12 39 / 42
  • 40. PostgREST DB Schema -> API Rediscover values of RDBMS Advantage: can utilize more mature tools built around RDBMS Jiang Wu Swagger 2015-09-12 40 / 42
  • 41. Apply DRY principle Abstract not duplicate Select proper tools Bring values Jiang Wu Swagger 2015-09-12 41 / 42
  • 42. Q&A Questions? Twitter: @masterwujiang Github: @nouse Linkedin: @nouse Jiang Wu Swagger 2015-09-12 42 / 42