SlideShare a Scribd company logo
1 of 42
Download to read offline
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.0Pece Nikolovski
 
Quick run in with Swagger
Quick run in with SwaggerQuick run in with Swagger
Quick run in with SwaggerMesh Korea
 
Design Driven API Development
Design Driven API DevelopmentDesign Driven API Development
Design Driven API DevelopmentSokichi Fujita
 
Streamlining API with Swagger.io
Streamlining API with Swagger.ioStreamlining API with Swagger.io
Streamlining API with Swagger.ioVictor 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 toolsSwagger API
 
A Tour of Swagger for APIs
A Tour of Swagger for APIsA Tour of Swagger for APIs
A Tour of Swagger for APIsAllen Dean
 
Introducing Swagger
Introducing SwaggerIntroducing Swagger
Introducing SwaggerTony Tam
 
Introducing swagger
Introducing swaggerIntroducing swagger
Introducing swaggerAmr Ali
 
Developing Faster with Swagger
Developing Faster with SwaggerDeveloping Faster with Swagger
Developing Faster with SwaggerTony 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 InflectorTony 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 BrowsableMatt Bishop
 
Designing APIs with OpenAPI Spec
Designing APIs with OpenAPI SpecDesigning APIs with OpenAPI Spec
Designing APIs with OpenAPI SpecAdam Paxton
 
Swagger 2.0: Latest and Greatest
Swagger 2.0: Latest and GreatestSwagger 2.0: Latest and Greatest
Swagger 2.0: Latest and GreatestLaunchAny
 
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 2015johannes_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/OpenAPIScott 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 GuideAndrii 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 2019Matt 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-2020b0ris_1
 
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
 
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
 
Seattle StrongLoop Node.js Workshop
Seattle StrongLoop Node.js WorkshopSeattle StrongLoop Node.js Workshop
Seattle StrongLoop Node.js WorkshopJimmy 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 testingPetrosPlakogiannis
 
OGCE Project Overview
OGCE Project OverviewOGCE Project Overview
OGCE Project Overviewmarpierc
 
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_workshopShubhra 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 DevelopmentHyunghun 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 ServicesRainer Stropek
 
Exposing GraphQLs as Managed APIs
Exposing GraphQLs as Managed APIsExposing GraphQLs as Managed APIs
Exposing GraphQLs as Managed APIsWSO2
 
Headless Drupal en pratique
Headless Drupal en pratiqueHeadless Drupal en pratique
Headless Drupal en pratiqueSimon 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 - AtlantaJudy 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 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
 
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...
 
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 numbaJiang Wu
 
用Ruby编写博客应用
用Ruby编写博客应用用Ruby编写博客应用
用Ruby编写博客应用Jiang Wu
 
Sinatra and friends
Sinatra and friendsSinatra and friends
Sinatra and friendsJiang Wu
 
Rubyconf China
Rubyconf ChinaRubyconf China
Rubyconf ChinaJiang Wu
 
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 sequelJiang 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

Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsAhmed Mohamed
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaHanief Utama
 
Cyber security and its impact on E commerce
Cyber security and its impact on E commerceCyber security and its impact on E commerce
Cyber security and its impact on E commercemanigoyal112
 
What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...Technogeeks
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...stazi3110
 
Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Velvetech LLC
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio, Inc.
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfAlina Yurenko
 
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Angel Borroy López
 
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...OnePlan Solutions
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEOrtus Solutions, Corp
 
Best Web Development Agency- Idiosys USA.pdf
Best Web Development Agency- Idiosys USA.pdfBest Web Development Agency- Idiosys USA.pdf
Best Web Development Agency- Idiosys USA.pdfIdiosysTechnologies1
 
Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesPhilip Schwarz
 
Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Andreas Granig
 
Introduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfIntroduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfFerryKemperman
 
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)jennyeacort
 
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Matt Ray
 
Odoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 EnterpriseOdoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 Enterprisepreethippts
 
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024StefanoLambiase
 

Recently uploaded (20)

Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML Diagrams
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief Utama
 
Cyber security and its impact on E commerce
Cyber security and its impact on E commerceCyber security and its impact on E commerce
Cyber security and its impact on E commerce
 
What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
 
Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
 
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort ServiceHot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
 
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
 
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
 
Best Web Development Agency- Idiosys USA.pdf
Best Web Development Agency- Idiosys USA.pdfBest Web Development Agency- Idiosys USA.pdf
Best Web Development Agency- Idiosys USA.pdf
 
Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a series
 
Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024
 
Introduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfIntroduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdf
 
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
 
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
 
Odoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 EnterpriseOdoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 Enterprise
 
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 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