GithubHelp home page GithubHelp logo

cristianogregnanin / rails-4-api Goto Github PK

View Code? Open in Web Editor NEW

This project forked from emilsoman/rails-4-api

0.0 3.0 0.0 104 KB

Template app for a tested, documented and versioned JSON API using Rails 4 and Rails-Api

License: MIT License

Ruby 83.42% HTML 7.52% Gherkin 9.06%

rails-4-api's Introduction

Rails 4 API

Build Status

After I published my blog post on Building a Tested, Documented and Versioned JSON API Using Rails 4, many readers asked me for a sample template app. So here it is. Feel free to send in pull requests.

This is a template Rails 4 app which has the following to start with :

  1. Rails-API - Rails for API only apps
  2. Devise for token based authentication
  3. Cucumber for integration testing + up-to-date API documentation
  4. Versioning using the "Accept" header
  5. Does not depend on cookies/session.( In simple words, the API client need not be a browser )

Getting started

cd rails-4-api
bundle install --without production
RAILS_ENV=test bundle exec rake db:setup #Setup the test DB
bundle exec rake #Build ( RSpec + Cucumber )
#open public/api_doc.html in your browser

Why use Cucumber ?

I get this question a lot : "Why use Cucumber for API testing ? Why not RSpec controller/request specs ?"

  1. Cucumber is good at one thing : integration testing using user interaction expressed as steps. API testing = integration testing , where the user = any API client that can interact with the API in the language of HTTP requests. Use Rack::Test for HTTP request/response instead of Capybara for page interaction, now you can write API client interaction as steps and write readable and expressive integration tests.
  2. I want to use the output of the test suite as documentation for my APIs. Cucumber output is perfect for this, because cucumber forces you to write sequences of steps in a natural language. You would need a hell lot of ruby blocks in RSpec to produce an output that can act as a self explanatory documentation.
  3. Personal choice. I use RSpec heavily for unit test and I find RSpec is a good fit for that. But writing integration tests in RSpec doesn't look good to me. But to each his own, there's nothing stopping you from using RSpec for the job. Read this excellent blog post to see how you can use RSpec to test APIs

rails-4-api's People

Contributors

emilsoman avatar

Watchers

James Cloos avatar Cristiano avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.