Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Frisby.js: BDD For Your REST API

94cb827736e36e0f6343e9640e72fec7?s=47 vlucas
June 09, 2012

Frisby.js: BDD For Your REST API

Frisby.js is a REST API testing framework built on node.js and Jasmine that makes testing API endpoints easy, fast, and fun. Use Frisby to step in the shoes of your developer community and ensure consistency in API response structures, keys, and types. Great for ensuring your APIs don’t change or break across versions, and remain reliable and consistent so your developer community can thrive.

94cb827736e36e0f6343e9640e72fec7?s=128

vlucas

June 09, 2012
Tweet

Transcript

  1. : BDD for your REST API Vance Lucas • Co-Founder,

    Brightbit http://brightb.it
  2. 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
  3. 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
  4. 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
  5. Behavior Driven Development

  6. 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
  7. BDD tests the user interface of your application

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

  9. Are you sure your API is working exactly like it

    is supposed to?
  10. Integers & Floats are not strings, Boolens are actually boolean,

    etc.
  11. 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
  12. 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)
  13. 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
  14. The Frisby.js API

  15. 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();
  16. Helpers / Config • globalSetup • setup • reset •

    timeout • addHeader • removeHeader • setHeaders • auth • after / afterJSON • get / post / put / delete • create / toss
  17. Expectations • expectStatus • expectHeader • expectHeaderContains • expectJSON •

    expectJSONTypes • expectBodyContains • expectJSONLength • expectMaxResponseTime
  18. Inspectors • inspectJSON • inspectBody • inspectRequest • inspectResponse •

    inspectStatus
  19. DEMO TIME!

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