20
5 Ways to Build Better Web APIs in Ruby

5 Ways to Build Better Web APIs with Ruby and Rails

Embed Size (px)

DESCRIPTION

5 ways to improve your Ruby and Rails web APIs: 1. Select the right framework and rubgems 2. Prototype your API first 3. Build acceptance tests 4. Utilize API tools for faster development 5. Build a great developer experience

Citation preview

Page 1: 5 Ways to Build Better Web APIs with Ruby and Rails

5 Ways to Build Better

Web APIs in Ruby

Page 2: 5 Ways to Build Better Web APIs with Ruby and Rails

1. Select the right API framework and gems

Page 3: 5 Ways to Build Better Web APIs with Ruby and Rails

Rails isn't always the right answer

Page 4: 5 Ways to Build Better Web APIs with Ruby and Rails

Not all frameworks are ==

Cuba

Rack::Response

Rambutan

NYNY

Rails

Ramaze

0 2000 4000 6000 8000 10000

Requests/sec (Higher is better)

Page 5: 5 Ways to Build Better Web APIs with Ruby and Rails

Neither are ORMs…

Class

Hash

AR 3.2

Datamapper

Sequel

0 1 2 3 4 5 6 7 8

new(hash)new()

Page 6: 5 Ways to Build Better Web APIs with Ruby and Rails

Select a Serializer

Select a gem or approach that can build JSON, XML, and (perhaps) any future format as well.

(I like Roar + Representable)

Page 7: 5 Ways to Build Better Web APIs with Ruby and Rails

Pro Tip: Select your frameworks and gems based on your actual

needs(not what someone else

says)

Page 8: 5 Ways to Build Better Web APIs with Ruby and Rails

2. Prototype Your API

Page 9: 5 Ways to Build Better Web APIs with Ruby and Rails

Ways to Prototype

Static files – manual response for GET only

Stubbed controllers – works for all request types

Heroku Dataclips – great for a quick way to build SQL-to-JSON for GET requests

Page 10: 5 Ways to Build Better Web APIs with Ruby and Rails

3. Acceptance test your APIs

Page 11: 5 Ways to Build Better Web APIs with Ruby and Rails

TDD APIs FTW!

Acceptance tests will ensure you write better APIs by mimicking how developers will consume your API

Page 12: 5 Ways to Build Better Web APIs with Ruby and Rails

What should you use?

RSpec, Cucumber, ???

One is not better than another

Use a testing framework so a failure should break your build and report on what failed

Page 13: 5 Ways to Build Better Web APIs with Ruby and Rails

4. Select the right API tools

Page 14: 5 Ways to Build Better Web APIs with Ruby and Rails

Examples of API Tools

Exploration: POSTman Chrome Plugin

Documentation: RAML, Runscope, APIDesigner

Debugging: RunScope, SOAPUI

Auth/token and portal mgmt: Layer 7, Apigee, Mashery, 3Scale, Stormpath

and many others…

Page 15: 5 Ways to Build Better Web APIs with Ruby and Rails

5. Improve the developer experience

Page 16: 5 Ways to Build Better Web APIs with Ruby and Rails

Rails trained us to think CRUD

Page 17: 5 Ways to Build Better Web APIs with Ruby and Rails

Stop painting your APIs with CRUD to solve problems

Page 18: 5 Ways to Build Better Web APIs with Ruby and Rails

Take an outside-in design

What is the problem?

How does the world view the problem?

How does your API solve their problem?

Page 19: 5 Ways to Build Better Web APIs with Ruby and Rails

Document your API

Build examples for quick wins

Speak in their terms

Page 20: 5 Ways to Build Better Web APIs with Ruby and Rails

Thank you.

[email protected]@launchany

http://bit.ly/better-ruby-apis