Skip to content

Instantly share code, notes, and snippets.

@aishek
Created September 29, 2014 10:27
Show Gist options
  • Save aishek/a17770a03a17da4065e6 to your computer and use it in GitHub Desktop.
Save aishek/a17770a03a17da4065e6 to your computer and use it in GitHub Desktop.
grape api example
# app/controllers/api/v1/cities_api.rb
class Api::V1::CitiesAPI < Api::V1::BaseAPI
resource :cities do
params do
optional :term, :type => String
end
get '/' do
cities = ::City.ordered_by_name_asc
cities = cities.unscoped.by_name(params[:term]) if params[:term].present?
present :cities, cities, :with => ::Api::V1::CityEntity
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment