Sha256: 0bc3f58682b78dd27ee397bd4412cc704ca5b8899cf05568481b83fbaeb0299e

Contents?: true

Size: 729 Bytes

Versions: 3

Compression:

Stored size: 729 Bytes

Contents

# -*- encoding : utf-8 -*-
# This illustrates simple get w/ params and post w/ body services
# It also illustrates having two services w/ the same endpoint (just different HTTP methods)
module DummyServices
  class Echo < Grape::API
    format :json
    content_type :txt, 'text/plain'

    helpers do
      def echo(message)
        error!('Bad Request', 400) unless message
        message
      end
    end

    # curl localhost:5000/api/echo --get --data-urlencode 'msg={"one fish": "two fish"}' -vv
    get '/echo' do
      echo params[:msg]
    end

    # curl localhost:5000/api/echo -H 'Content-Type: text/plain' -d '{"red fish": "blue fish"}' -vv
    post '/echo' do
      echo env['api.request.body']
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
pacto-0.4.0.rc3 sample_apis/echo_api.rb
pacto-0.4.0.rc2 sample_apis/echo_api.rb
pacto-0.4.0.rc1 sample_apis/echo_api.rb