swagger apis for humans and robots (gluecon)

29
Swagger APIs for Humans (and Robots) @fehguy

Upload: tony-tam

Post on 11-May-2015

3.803 views

Category:

Technology


1 download

DESCRIPTION

Presentation to Gluecon 2014 about Swagger for API development and adoption of services. Reverb also announced the Swagger 2.0 Working Group, with Apigee as a founding member

TRANSCRIPT

Page 1: Swagger APIs for Humans and Robots (Gluecon)

Swagger APIs for Humans

(and Robots)

@fehguy

Page 2: Swagger APIs for Humans and Robots (Gluecon)

Swagger Philosophy

Page 3: Swagger APIs for Humans and Robots (Gluecon)

Swagger Philosophy

Service documentation sucks

typically

Page 4: Swagger APIs for Humans and Robots (Gluecon)

Swagger Philosophy

• Communicating is too much work– Users don’t want to write YOUR SDK– If you’re good at Ruby, you suck at GO

• Consumers need a contract– Service logic doesn’t belong in the SDK

• Services are plumbing– We shouldn’t all be plumbers– Business logic is your business

Page 5: Swagger APIs for Humans and Robots (Gluecon)

Swagger Philosophy

• Solved by machine-readable, discoverable API contract

• Should speed up, not slow down development process

• External services/proxies not required

Page 6: Swagger APIs for Humans and Robots (Gluecon)

What is Swagger?

• An interface to your service– Described in JSON

• It is a contract to your service• Enables “bigotry-free” restful design with

emphasis on getting things done– Many ways to delete a Pet

Page 7: Swagger APIs for Humans and Robots (Gluecon)

How does it work?

• Discoverable at runtime, not compile-time• It’s just JSON• No server integration required

– You can describe an API that’s not even yours– Deploy anywhere! Put it on github!– Swagger is JUST a way to describe an API

Page 8: Swagger APIs for Humans and Robots (Gluecon)

But Why?

• Machine-readable contract– Description of *everything* the server

can do– Server-controlled documentation– Server/language/platform/deployment

agnostic

• Documentation, code generation, client generation– Like Headers for C, Interfaces for

Java

Page 9: Swagger APIs for Humans and Robots (Gluecon)

Swagger UI

Page 10: Swagger APIs for Humans and Robots (Gluecon)

Client SDKs

• Your consumers want to use your service– How they want– Not write your software

Page 11: Swagger APIs for Humans and Robots (Gluecon)

How do you add Swagger?

• Static Files– Manually crafted JSON

• Heuristics– Traffic inspection

• Code inspection– Code comments, static annotations

• Runtime generation

It’s just JSON!

Page 12: Swagger APIs for Humans and Robots (Gluecon)

Client Generation

https://github.com/wordnik/swagger-codegen • Templates can be generated your way• Typed and untyped languages

Groovy Java Androidasync-scala C# FlashObjective C PHP PythonPython 3 Ruby Scala

Page 13: Swagger APIs for Humans and Robots (Gluecon)

Client Generation

• Requires a proper API definition• Type info, parameters, input/output models• Protocol, path, authentication• Templates are a starting point

– Clone, configure, put in workflow

Page 14: Swagger APIs for Humans and Robots (Gluecon)

Client Generation

• Configuration Script– Packages– Imports– Type Mapping– Packaging info

• Group ID, Artifact ID, version

• Templates– Boilerplate code

Page 15: Swagger APIs for Humans and Robots (Gluecon)

Client Generation

• Codegen for client generation

Page 16: Swagger APIs for Humans and Robots (Gluecon)

Static Doc Generation

• Codegen !== client generation• Templates are generic

Page 17: Swagger APIs for Humans and Robots (Gluecon)

Static Doc Generation

Page 18: Swagger APIs for Humans and Robots (Gluecon)

Server Generation

• Specs can generate servers

Page 19: Swagger APIs for Humans and Robots (Gluecon)

How do you write Software?

• Code first?• Design first?• Hybrid?

One size does NOT fit all

Page 20: Swagger APIs for Humans and Robots (Gluecon)

Top Down vs. Bottom-up

• Design-first is not this (anymore)

Page 21: Swagger APIs for Humans and Robots (Gluecon)

Top Down

• GUI vs. XML? The world chose GUI!• GUI vs. JSON?• GUI vs. YAML?

Page 22: Swagger APIs for Humans and Robots (Gluecon)

Top Down?

XML: 453 Lines JSON: 512 Lines YAML: 400 Lines

It’s not about the line count!

Page 23: Swagger APIs for Humans and Robots (Gluecon)

Introducing Swagger Editor!

Page 24: Swagger APIs for Humans and Robots (Gluecon)

Evolution of Swagger

• Swagger Editor– Angular, Ace– OSS, Apache 2.0

• Thank you Community!– 500k downloads of java framework alone– ~10k production deployments– 4k stars, 1600 forks– Big & Small

Page 25: Swagger APIs for Humans and Robots (Gluecon)
Page 26: Swagger APIs for Humans and Robots (Gluecon)

Swagger 2.0 Working Group

• Give your input on Swagger 2.0 Specification

• Coming this Summer• More info:

– http://swagger.wordnik.com

• Join the evolution– https://github.com/wordnik/swagger-spec

Page 27: Swagger APIs for Humans and Robots (Gluecon)

Swagger has a Community

• Server integrations

JAX-RS (java) Scalatra (scala) Spring MVC (java)Spray (scala) Composer (PHP) django (python)Flask (python) Go Maven (JAX-RS)ServiceStack (.net) Doctrine (PHP) Express (JS)Restler (PHP) Hapi (JS) Clojure