Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Curlin' for Docs


Published on

You may have docs for your API, but do you have an API for your docs? With RspecApiDocumentation and Raddocs, you can cURL for your documentation. SmartLogic's Eric Oestrich tells you how. Check out the slides, or read about it here:

Published in: Technology, News & Politics
  • Be the first to comment

  • Be the first to like this

Curlin' for Docs

  1. 1. cURLin for Docs Eric Oestrich @ericoestrich
  2. 2. Say what?$ curl -H "Accept: text/docs+plain"
  3. 3. ExampleGetting a list of orders------------------------Parameters: * page - Current page of orders
  4. 4. RequestRequest: GET /orders?page=1 Accept: application/json Content-Type: application/json Cookie: Host: page=1
  5. 5. ResponseResponse: Status: 200 OK Cache-Control: max-age=0, private, must-revalidate Content-Length: 121 Content-Type: application/json; charset=utf-8 ETag: "6cd5831e98b0090b64672b5604d9eb2a" X-Runtime: 0.019010 X-UA-Compatible: IE=Edge,chrome=1 [{"email":"","name":"Order 0","paid":true},{"email":"","name":"Order 1","paid":true}]
  6. 6. Neat-o, how do I get that?
  7. 7. Install some gemsGemfilegroup :test do gem rspec_api_documentation gem raddocsend
  8. 8. Write RAD testsspec/acceptance/orders_spec.rbresource "Orders" do get "/orders" do it "should ..." do ... end endend
  9. 9. Configure the output formatsspec/spec_helper.rbRspecApiDocumentation.configure do |config| config.formats = [:json, :combined_text]end
  10. 10. Generate docs$ rake docs:generate
  11. 11. Mount Raddocsconfig/routes.rbApplication.routes.draw do resources :orders match "/docs" => Raddocs::App, :anchor => falseend
  12. 12. Use Raddocs::Middlewareconfig/application.rbmodule Example class Application < Rails::Application ... config.middleware.use "Raddocs::Middleware" ... endend
  13. 13. cURL Away$ curl -H "Accept: text/docs+plain" http://localhost/orders
  14. 14. Demo
  15. 15. Gems● rspec_api_documentation ○● raddocs ○
  16. 16. Questions?