Created
August 21, 2014 14:06
-
-
Save ik5/3ddbd25ab1455f7ab438 to your computer and use it in GitHub Desktop.
Example for simple usage of Grape
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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