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

Frisby.js: BDD For Your REST API

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.

vlucas

June 09, 2012
Tweet

More Decks by vlucas

Other Decks in Programming

Transcript

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

    View Slide

  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

    View Slide

  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

    View Slide

  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

    View Slide

  5. Behavior Driven
    Development

    View Slide

  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

    View Slide

  7. BDD tests the user
    interface of your
    application

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

  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

    View Slide

  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)

    View Slide

  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

    View Slide

  14. The Frisby.js API

    View Slide

  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();

    View Slide

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

    View Slide

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

    View Slide

  18. Inspectors
    • inspectJSON
    • inspectBody
    • inspectRequest
    • inspectResponse
    • inspectStatus

    View Slide

  19. DEMO TIME!

    View Slide

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

    View Slide