Swagger for-your-api

23
Swagger for your REST API Tony Tam

description

Slides from http://apistrategyconference.com/ on swagger in your REST api

Transcript of Swagger for-your-api

Page 1: Swagger for-your-api

Swagger for your REST API Tony Tam

Page 2: Swagger for-your-api

REST as the “new” API

Revisiting the JAR

•  Expose & share low-level functionality

•  Reduced plumbing, focus on business logic

•  Helped us build big, monolithic apps

•  Dependency hell

Page 3: Swagger for-your-api

REST as the “new” API

•  Complex building blocks for your application •  Authentication •  Photo storage •  Analytics

•  Language & deployment independent

•  Vertical scaling addressed by smaller, decoupled services

Page 4: Swagger for-your-api

Integrating 3rd Party APIs

How about Documentation?"

Page 5: Swagger for-your-api

Integrating 3rd Party APIs

How about Documentation?"

Javadocs?"

Stack Overflow?"

IDE support?"

JSDoc?"

Page 6: Swagger for-your-api

Integrating 3rd Party APIs

Page 7: Swagger for-your-api

Integrating 3rd Party APIs

Page 8: Swagger for-your-api

Integrating 3rd Party APIs

Page 9: Swagger for-your-api

Integrating 3rd Party APIs

Page 10: Swagger for-your-api

So… How do we describe APIs?

Developer Docs?"

WADL"WADL2?"

WSDL?"

Javadocs?"

Page 11: Swagger for-your-api

The Swagger Specification

It’s a spec! •  JSON •  Coupled of decoupled •  Machine-readable •  Language agnostic •  Distributed by Design

An Interface for your API

Page 12: Swagger for-your-api

Benefits of an Interface

It’s done in JSON •  Generate manually

•  Deploy statically •  Generate automatically by server integration

•  9 languages, 16+ frameworks

Existing API?

Page 13: Swagger for-your-api

Benefits of an Interface

Machine-readable Your boss can try your

API

Page 14: Swagger for-your-api

Swagger Spec Server"

Benefits of an Interface

Distributed design

/pet"

/store"

/user"

Server 1"

Server 2"

Server 3"

Resource"Listing"

API Declaration"

Page 15: Swagger for-your-api

How does this help you?

Client-Side Developer"

Server"Developer"

Page 16: Swagger for-your-api

How does this help you?

Client-Side Developer"

OMG I can code w/o waiting for back end!"

The client developer

isn’t bugging me!"

Server"Developer"

Page 17: Swagger for-your-api

How about your clients?

REST or SDK? •  Please! Strive to

remove your logic from clients

/api/pet.json/1?delete (GET) /api/pet.json/1 (DELETE) /api/pet.json/1 (POST empty)

Page 18: Swagger for-your-api

How about your clients?

REST or SDK? •  Please! Strive to

remove your logic from clients

/api/pet.json/1?delete (GET) /api/pet.json/1 (DELETE) /api/pet.json/1 (POST empty) These all

“work” (This is your job, not your

clients’)

Page 19: Swagger for-your-api

How about your clients?

Swagger can help (if you like) •  Machine-readable => code generator •  Uses non-ghetto {{mustache}} templates •  Make client libraries “your way”

Page 20: Swagger for-your-api

How about your API service?

Swagger can again help (if you like) •  Code-generator, not “client generator” •  Build your server from the interface

Page 21: Swagger for-your-api

Interfaces are nice

•  Developers know what they’re building •  Clients know what they’re getting •  Machines and humans can interpret them •  Teams can develop in parallel

Page 22: Swagger for-your-api

Swagger is FOSS

Page 23: Swagger for-your-api

Where to go next More info + demo http://developers.helloreverb.com/swagger/

Swagger specification https://github.com/wordnik/swagger-core/wiki

JVM server implementation https://github.com/wordnik/swagger-core

Node.js server implementation https://github.com/wordnik/swagger-core

swagger-ui https://github.com/wordnik/swagger-ui

swagger-codegen https://github.com/wordnik/swagger-codegen

@fehguy"