Slide 1

Slide 1 text

: BDD for your REST API Vance Lucas • Co-Founder, Brightbit http://brightb.it

Slide 2

Slide 2 text

Who are You? • Vance Lucas • http://vancelucas.com • @vlucas (for heckling) • Brightbit • http://brightb.it • Design, Development & Consulting for web apps, mobile apps and APIs

Slide 3

Slide 3 text

What is Frisby.js? • Firsby.js is a JSON REST API testing tool written in JavaScript using Jasmine and node.js • npm install frisby • API Docs: http://frisbyjs.com/ • Fork me: https://github.com/vlucas/frisby

Slide 4

Slide 4 text

Why Make Frisby.js? • Developed for a Brightbit client during a major API code refactoring • Needed to ensure unmodified API outputs were the same in both old & new versions • Needed to ensure apps would not break • Client’s production API traffic • 2k+ req/s baseline (24/7) • 4-5k req/s peak

Slide 5

Slide 5 text

Behavior Driven Development

Slide 6

Slide 6 text

BDD is driven by business value; that is, the benefit to the business which accrues once the application is in production. The only way in which this benefit can be realized is through the user interface(s) to the application, usually (but not always) a GUI. http://en.wikipedia.org/wiki/Behavior_Driven_Development

Slide 7

Slide 7 text

BDD tests the user interface of your application

Slide 8

Slide 8 text

A developer’s user interface to your application is your API

Slide 9

Slide 9 text

Are you sure your API is working exactly like it is supposed to?

Slide 10

Slide 10 text

Integers & Floats are not strings, Boolens are actually boolean, etc.

Slide 11

Slide 11 text

Frisby.js Can... • Ensure that your API is working (with seamless integration into Continuous Integration tools like Jenkins, etc.) • Check return values • Check return types and object structures • Test your full stack instead of just code • Act as basic developer API documentation • Help users report bugs with code

Slide 12

Slide 12 text

Full Stack Testing • See and use your own API from the perspective of your developers • Test through the caching layer - enables tests for cache invalidation issues • Encourages you to setup a proper test/ development environment (to not create and delete real items via your API)

Slide 13

Slide 13 text

Bug Reporting • Put your Frisby tests in an a public GitHub repository & share the URL • Developers can fork your repo, enter their auth details, and run the API tests • You may want a test/dev (non-production) API url for this • Developers can submit pull requests to report bugs in your API with Frisby tests • You can review, fix the issue, and merge in their code to prevent regressions

Slide 14

Slide 14 text

The Frisby.js API

Slide 15

Slide 15 text

Simple Syntax frisby.create('List objects from webservice') .get('http://mywebservice.com/example.json') .expectStatus(200) .expectJSONTypes('items.*', { id: Number, name: String, has_stuff: Boolean, }) .toss();

Slide 16

Slide 16 text

Helpers / Config • globalSetup • setup • reset • timeout • addHeader • removeHeader • setHeaders • auth • after / afterJSON • get / post / put / delete • create / toss

Slide 17

Slide 17 text

Expectations • expectStatus • expectHeader • expectHeaderContains • expectJSON • expectJSONTypes • expectBodyContains • expectJSONLength • expectMaxResponseTime

Slide 18

Slide 18 text

Inspectors • inspectJSON • inspectBody • inspectRequest • inspectResponse • inspectStatus

Slide 19

Slide 19 text

DEMO TIME!

Slide 20

Slide 20 text

Questions? Rate this talk: https://joind.in/6239