• Stars
    star
    728
  • Rank 61,697 (Top 2 %)
  • Language
    Ruby
  • Created about 12 years ago
  • Updated over 9 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

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

ApiTaster endorse Build Status Dependency Status

NOTE

If you want to use this gem with Rails 3x/4.0 please specify version 0.7.0 in your Gemfile.

Version 0.8 of this gem is compatible only with Rails 4.1.

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

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 lib/api_tasters/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

You can change the default lib/api_tasters/routes.rb path by creating config/initializers/api_taster.rb with the content below:

ApiTaster.route_path = Rails.root.to_s + "/app/api_tasters" # just an example

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.

Custom Headers

If there are certain headers (such as auth token) that need to be present to consume an API endpoint, you may set then in APITaster.global_headers before APITaster.routes:

ApiTaster.global_headers = {
  'Authorization' => 'Token token=teGpfbVitpnUwm7qStf9'
}

ApiTaster.routes do
  # your route definitions
end

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.

License

This gem is released under the MIT License.

Author

Fred Wu, originally built for Locomote.

Bitdeli Badge

More Repositories

1

crawler

A high performance web crawler / scraper in Elixir.
Elixir
917
star
2

jquery-endless-scroll

Endless/infinite scrolling/pagination.
CoffeeScript
838
star
3

angel_nest

Project code name: Angel Nest. :)
Ruby
775
star
4

simple_bayes

A Naive Bayes machine learning implementation in Elixir.
Elixir
392
star
5

datamappify

Compose, decouple and manage domain logic and data persistence separately. Works particularly great for composing form objects!
Ruby
332
star
6

opq

Elixir queue! A simple, in-memory queue with worker pooling and rate limiting in Elixir.
Elixir
255
star
7

stemmer

An English (Porter2) stemming implementation in Elixir.
Elixir
149
star
8

bustle

Activities recording and retrieving using a simple Pub/Sub-like interface.
Ruby
93
star
9

ruby_decorators

Ruby method decorators inspired by Python.
Ruby
63
star
10

inherited_resources_views

Share and DRY up views between resources. Use with Inherited Resources.
Ruby
60
star
11

jquery-inline-confirmation

Inline Confirmation plugin for jQuery. One of the less obtrusive ways of implementing confirmation dialogues.
JavaScript
53
star
12

toy-robot-elixir

The infamous Toy Robot code test done in Elixir.
Elixir
45
star
13

skinny-coffee-machine

A simple JavaScript state machine with observers, for browsers and Node.js.
JavaScript
42
star
14

kohana-phamlp

This module is a bridge between the Kohana PHP framework (http://kohanaframework.org/) and the PHamlP library (http://code.google.com/p/phamlp/).
PHP
25
star
15

authlite

Authlite, an auth module for Kohana PHP framework, it offers greater flexibility than the official Auth module.
PHP
23
star
16

dotfiles

My dotfiles
Shell
18
star
17

amaze_hands

Amaze Hands is an amazing tool developed for analysing Kanban board cards.
Ruby
15
star
18

kthrottler

A Kohana port of Action Throtller (for Rails): http://github.com/fredwu/action_throttler
PHP
14
star
19

jquery-slideshow-lite

An extremely lightweight slideshow plugin for jQuery.
JavaScript
14
star
20

code-test-2016-cultureamp

Ruby
13
star
21

README-xplor

Fred @ Xplor - how to work with me.
10
star
22

code-test-2016-myob

Ruby
8
star
23

code-test-2016-trunkplatform

Ruby
6
star
24

action_throttler

An easy to use Rails plugin to quickly throttle application actions based on configurable duration and limit.
Ruby
6
star
25

app_reset

Resets (and if available, seeds) your databases.
Ruby
6
star
26

yield.rb

Aggregated token amounts and values. Supports ApeBoard, YieldWatch, Binance, CoinGecko and more.
Ruby
5
star
27

layerful

Layerful PHP framework.
4
star
28

advent_of_code_2018

https://adventofcode.com/2018/about
Elixir
4
star
29

security_guard

A collection of useful tools for auditing data and performing security checks.
Ruby
3
star
30

fredwu.me-v3

JavaScript
3
star
31

ruby-slim-tmbundle

https://github.com/slim-template/ruby-slim.tmbundle
3
star
32

kata-poker-hands-elixir

A coding kata for comparing poker hands - Elixir version.
Elixir
2
star
33

flower

Playground to test out the Lotus framework.
Ruby
2
star
34

jqstub

A simple stub library for jQuery / Zepto objects.
JavaScript
1
star
35

project_retard

One sale a day e-commerce platform built on Ruby on Rails.
JavaScript
1
star
36

reacraft

Ruby
1
star
37

kata-poker-hands-ruby

A coding kata for comparing poker hands - Ruby version.
Ruby
1
star
38

toy-robot-lolz

It's art. And it's beautiful.
Ruby
1
star
39

code-test-2016-adslot

CoffeeScript
1
star
40

spiky_xml

Just a spike on XML parsing in different environments.
JavaScript
1
star