Module: ApiSampler

Defined in:
lib/api_sampler.rb,
lib/api_sampler/engine.rb,
lib/api_sampler/version.rb,
lib/api_sampler/middleware.rb,
lib/api_sampler/request_tag.rb,
lib/api_sampler/configuration.rb,
lib/api_sampler/matched_route.rb,
lib/api_sampler/route_resolver.rb,
lib/api_sampler/request_matcher.rb,
lib/generators/api_sampler/install/install_generator.rb

Overview

Collect samples (request/response pairs) for API endpoints of your Rails app.

Installation

Add this line to your application's Gemfile:

gem 'api_sampler'

And then execute:

$ bundle install

Finally, you need to run the generator:

$ rails generate api_sampler:install

This will create an initializer at config/initializers/api_sampler.rb, mount Engine at /api_sampler, copy and run the engine's migrations.

Run the following command to see the list of available options:

$ rails generate api_sampler:install --help

Configuration.

Edit the provided initializer at config/initializers/api_sampler.rb.

See Configuration for the list of available configuration options with the examples of their usage.

Defined Under Namespace

Classes: Configuration, Engine, InstallGenerator, MatchedRoute, Middleware, RequestMatcher, RequestTag, RouteResolver

Constant Summary collapse

HTTP_METHODS =

Valid HTTP methods.

%w(GET HEAD PUT POST DELETE OPTIONS PATCH LINK UNLINK).freeze
VERSION =
'0.1.0'

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.configConfiguration

Returns the configuration of api_sampler.

Returns:


57
58
59
# File 'lib/api_sampler.rb', line 57

mattr_accessor :config, instance_accessor: false do
  Configuration.new
end

Class Method Details

.configure {|config| ... } ⇒ void

This method returns an undefined value.

Configure api_sampler.

Examples:

ApiSampler.configure do |config|
  # configuration goes here
  config.allow %r{^/api/v1/}
  # more configuration...
end

Yields:

Yield Parameters:

Yield Returns:

  • (void)

Raises:

  • (ArgumentError)

    if block is not given.

See Also:


80
81
82
83
# File 'lib/api_sampler.rb', line 80

def configure
  raise ArgumentError, 'block is required' unless block_given?
  yield config
end