Skip to content

Instantly share code, notes, and snippets.

@ik5 ik5/Gemfile
Created Aug 21, 2014

Embed
What would you like to do?
Example for simple usage of Grape
module POC
class Example1 < Grape::API
version 'v1'
format :json
desc 'root location'
get '/' do
error!({status: 400, message: 'Bad Request.'}, 400)
end
desc 'namespace for authentication purpose'
namespace '/' do
http_basic do |name, pass|
{'admin' => 'admin'}[name] == pass
end
desc 'list all files located under current directory'
get 'ls' do
files = {}
files[:files] = Dir[File.dirname(__FILE__) + '/**']
files
end
end
end
end
#!/usr/bin/env ruby
require 'rubygems'
require 'bundler/setup'
Bundler.setup(:default)
require 'grape'
require 'json'
require File.dirname(__FILE__) + '/app.rb'
# you can execute it using: $ rackup config.ru
run POC::Example1
source "https://rubygems.org"
gem 'grape'
gem 'rack'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.