Created
September 29, 2014 10:27
-
-
Save aishek/a17770a03a17da4065e6 to your computer and use it in GitHub Desktop.
grape api example
This file contains 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
# 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