Git Product home page Git Product logo

api_taster's Introduction

ApiTaster endorse Build Status Dependency Status

A quick and easy way to visually test your Rails application's API.

Forked changes

  • Removed restriction around ActionDispatch::Routing::Mapper::Constraints to allow Devise routes to appear.
  • Removed dependency on latest jquery version and force 1.8 because of references to $.live()
  • Simplified user interface to focus only on json testing.

Original documentation:

Why?

There are already many awesome API clients (such as Postman), so why reinvent the wheel?

API Taster compared to alternatives, have the following advantages:

  • API endpoints are automatically generated from your Rails routes definition
  • Defining params is as easy as defining routes
  • Params can be shared with your test factories

Usage

Add API Taster in your gemfile:

gem 'api_taster'

Mount API Taster, this will allow you to visit API Taster from within your app. For example:

Rails.application.routes.draw do
  mount ApiTaster::Engine => "/api_taster" if Rails.env.development?
end

In routes.rb, define parameters for each API endpoint after the normal routes definition block. For example:

if Rails.env.development?
  ApiTaster.routes do
    desc 'Get a __list__ of users'
    get '/users'

    post '/users', {
      :user => {
        :name => 'Fred'
      }
    }

    get '/users/:id', {
      :id => 1
    }

    put '/users/:id', {
      :id => 1, :user => {
        :name => 'Awesome'
      }
    }

    delete '/users/:id', {
      :id => 1
    }
  end
end

Share Params with Test Factories

If you use a test factory such as FactoryGirl, you can require your test factories and share the params. For example in FactoryGirl you can use the attributes_for(:name_of_factory) method.

Global Params

If there are certain params (such as API version and auth token) that need to be present in every API endpoint, you may set them in ApiTaster.global_params before ApiTaster.routes:

ApiTaster.global_params = {
  :version    => 1,
  :auth_token => 'teGpfbVitpnUwm7qStf9'
}

ApiTaster.routes do
  # your route definitions
end

Commenting API Endpoints

Before each route definitions, you may use desc to add some comments. Markdown is supported.

desc 'Get a __list__ of users'
get '/users'

Metadata for API Endpoints

For each route definition, you may supply an optional third parameter (hash) as metadata:

get '/users', {}, { :meta => 'data' }

The metadata option is useful for passing in arbitrary data for a route definition. For example, you could specify response expectations so that your test suite could tap into them.

Metadata for every route definition are stored in ApiTaster::Route.metadata. Please read the source code to find out how to get metadata for a particular route.

Missing Route Definitions Detection

Instead of manually finding out which route definitions you need, API Taster provides a warning page that shows you all the missing definitions.

Obsolete / Mismatched Route Definitions Detection

APIs evolve - especially during the development stage. To keep ApiTaster.routes in sync with your route definitions, API Taster provides a warning page that shows you the definitions that are obsolete/mismatched therefore you could correct or remove them.

Changes by gajananbhat

Added Drop Down to select REST call to be submiited as JSON or HTML.

Added Drop down as a parameter to be displayed in the Form.

E.g.

desc 'Get a __list__ of users based on type.'
get '/users',
{
  :type => ['admin','supervisors']
}

This will show a dropdown in the form with the array elements as select values.

License

This gem is released under the MIT License.

Author

Fred Wu, originally built for Locomote.

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.