Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9204853
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T23:48:39+00:00 2026-06-17T23:48:39+00:00

I am trying to use grape for making Rest API. For this in a

  • 0

I am trying to use grape for making Rest API.

For this in a directory, I created a config.ru file:

require 'rubygems' 
require 'rack'
require './grape_sample'
run Twitter::API

There is a file named as grape_sample.rb:

module Twitter
class API < Grape::API

version 'v1', :using => :header, :vendor => 'twitter'
format :json

helpers do
  def current_user
    @current_user ||= User.authorize!(env)
  end

  def authenticate!
    error!('401 Unauthorized', 401) unless current_user
  end
end

resource :statuses do

  desc "Return a public timeline."
  get :public_timeline do
    Status.limit(20)
  end

  desc "Return a personal timeline."
  get :home_timeline do
    authenticate!
    current_user.statuses.limit(20)
  end

  desc "Return a status."
  params do
    requires :id, :type => Integer, :desc => "Status id."
  end
  get ':id' do
    Status.find(params[:id])
  end

  desc "Create a status."
  params do
    requires :status, :type => String, :desc => "Your status."
  end
  post do
    authenticate!
    Status.create!({
      :user => current_user,
      :text => params[:status]
    })
  end

  desc "Update a status."
  params do
    requires :id, :type => String, :desc => "Status ID."
    requires :status, :type => String, :desc => "Your status."
  end
  put ':id' do
    authenticate!
    current_user.statuses.find(params[:id]).update({
      :user => current_user,
      :text => params[:status]
    })
  end

  desc "Delete a status."
  params do
    requires :id, :type => String, :desc => "Status ID."
  end
  delete ':id' do
    authenticate!
    current_user.statuses.find(params[:id]).destroy
  end

end
end
end

When i run command rackup config.ru, then this error occurs:

/home/ritesh/rails/grape_sample.rb:2:in `<module:Twitter>': uninitialized constant Twitter::Grape (NameError)
    from /home/ritesh/rails/grape_sample.rb:1:in `<top (required)>'
    from /home/ritesh/.rvm/rubies/ruby-1.9.3-p327/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
    from /home/ritesh/.rvm/rubies/ruby-1.9.3-p327/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
    from /home/ritesh/rails/config.ru:7:in `block in <main>'
    from /home/ritesh/.rvm/gems/ruby-1.9.3-p327/gems/rack-1.5.0/lib/rack/builder.rb:55:in `instance_eval'
    from /home/ritesh/.rvm/gems/ruby-1.9.3-p327/gems/rack-1.5.0/lib/rack/builder.rb:55:in `initialize'
    from /home/ritesh/rails/config.ru:in `new'
    from /home/ritesh/rails/config.ru:in `<main>'
    from /home/ritesh/.rvm/gems/ruby-1.9.3-p327/gems/rack-1.5.0/lib/rack/builder.rb:49:in `eval'
    from /home/ritesh/.rvm/gems/ruby-1.9.3-p327/gems/rack-1.5.0/lib/rack/builder.rb:49:in `new_from_string'
    from /home/ritesh/.rvm/gems/ruby-1.9.3-p327/gems/rack-1.5.0/lib/rack/builder.rb:40:in `parse_file'
    from /home/ritesh/.rvm/gems/ruby-1.9.3-p327/gems/rack-1.5.0/lib/rack/server.rb:277:in `build_app_and_options_from_config'
    from /home/ritesh/.rvm/gems/ruby-1.9.3-p327/gems/rack-1.5.0/lib/rack/server.rb:199:in `app'
    from /home/ritesh/.rvm/gems/ruby-1.9.3-p327/gems/rack-1.5.0/lib/rack/server.rb:314:in `wrapped_app'
    from /home/ritesh/.rvm/gems/ruby-1.9.3-p327/gems/rack-1.5.0/lib/rack/server.rb:250:in `start'
    from /home/ritesh/.rvm/gems/ruby-1.9.3-p327/gems/rack-1.5.0/lib/rack/server.rb:141:in `start'
    from /home/ritesh/.rvm/gems/ruby-1.9.3-p327/gems/rack-1.5.0/bin/rackup:4:in `<top (required)>'
    from /home/ritesh/.rvm/gems/ruby-1.9.3-p327/bin/rackup:19:in `load'
    from /home/ritesh/.rvm/gems/ruby-1.9.3-p327/bin/rackup:19:in `<main>'
    from /home/ritesh/.rvm/gems/ruby-1.9.3-p327/bin/ruby_noexec_wrapper:14:in `eval'
    from /home/ritesh/.rvm/gems/ruby-1.9.3-p327/bin/ruby_noexec_wrapper:14:in `<main>'

This time, I include the require file in config.ru, but still see the error.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T23:48:41+00:00Added an answer on June 17, 2026 at 11:48 pm

    You haven’t required the rubygem that implements Grape.

    Add the line

    require 'grape'

    to grape_sample.rb

    If you continue to have problems, make sure that you have installed the grape gem:

    gem install grape

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to use the Facebook graph api to publish a swf file
Im trying to do a simple script with this: How-To: Use the Graph API
i'm trying use facebook API to upload photo in my fan page. I downloaded
I'm trying use mod_rewrite to rewrite URLs from the following: http://www.site.com/one-two-file.php to http://www.site.com/one/two/file.php The
I am need paint my image. I'm trying use JQuery in here this link:
I am trying to use Google graph API (image) to show some data in
I'm trying to use the Graph API and the PHP SDK for Facebook to
I'm fairly new to Facebook's Graph API. I'm trying to use their Graph API
I am trying to use networkx with Python. When I run this program it
I am trying to use graph batch api , is there any reference code

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.