Your use of resource
and route
methods is ok.
You have a problem with parameter processing - params[:id]
is a String
by default. Your example hard-coded value that works is aFixnum
(integer).
Probably your (not shown) code that queries the list on ITEMS is looking up integer values.
You could use ITEMS.find_one( "item_id" => params[:id].to_i )
to convert the param inline.
However, you probably should use a params
description block to get Grape to convert for you, as you already are for OBJECTS:
desc "Returns an item by its id."
params do
requires :id, type: Integer
end
get '/:id' do
ITEMS.find_one( "item_id" => params[:id] )
end