class Restspec::Endpoints::EndpointDSL

The Endpoint DSL is what should be used inside an endpoint block. Its major responsability is to define endpoint behavior.

Public Instance Methods

headers() click to toggle source

A mutable hash containing the headers for the endpoint

@example

endpoint :monkeys do
  headers['Content-Type'] = 'application/json'
end
# File lib/restspec/endpoints/dsl.rb, line 302
def headers
  endpoint.headers
end
method(method) click to toggle source

@example

endpoint :show do
  method :get
end

@param method [Symbol] the http method name

# File lib/restspec/endpoints/dsl.rb, line 252
def method(method)
  endpoint.method = method
end
no_schema() click to toggle source

Remove the schema of the current endpoint. Some endpoints doesn't require schemas for payload or for responses. This is the typical case for DELETE requests.

@example

resource :game do
  delete(:destroy) { no_schema }
end
# File lib/restspec/endpoints/dsl.rb, line 292
def no_schema
  endpoint.remove_schemas
end
path(path) click to toggle source

Defines what the path will be. It will be append to the namespace's `base_path` and to the Restspec config's `base_url`.

@example

endpoint :monkeys do
  path '/monkeys'
end

@param path [String] the path of the endpoint

# File lib/restspec/endpoints/dsl.rb, line 266
def path(path)
  endpoint.path = path
end
schema(name, options = {}) click to toggle source

Defines what the schema will be.

@example

endpoint :monkeys do
  schema :monkey
end

@param name [Symbol] The schema's name. @param options [Hash] A set of options to pass to {Endpoint#add_schema}.

# File lib/restspec/endpoints/dsl.rb, line 279
def schema(name, options = {})
  endpoint.add_schema(name, options)
end
url_param(param, &value_or_type_block) click to toggle source

This set url parameters for the endpoint. It receives a key and a block returning the value. If the value is a type, an example will be generated.

@example with just a value:

endpoint :monkeys, path: '/:id' do
  url_param(:id) { '1' }
end # /1

@example with a type:

endpoint :monkeys, path: '/:id' do
  url_param(:id) { string } # a random string
end # /{the random string}

@param param [Symbol] the parameter name. @param value_or_type_block [block] the block returning the value.

# File lib/restspec/endpoints/dsl.rb, line 321
def url_param(param, &value_or_type_block)
  endpoint.add_url_param_block(param) do
    ExampleOrValue.new(endpoint, param, value_or_type_block).value
  end
end