I have a service that uses kaminari for pagination. The index
controller action for the service looks like this.
respond_to :json, xml
def index
if params[:query].present?
@search = Product.search_for(params[:query], load: true)
else
@search = Product.all
end
@products = Kaminari.paginate_array(@search).page(params[:page]).per(20)
end
i am using rabl to create json views. The index.rabl
looks like this:
collection @products => :products
attributes :title, :price, :category_id
I also have a client that consumes the service; part of the client's controller action that consumes the service looks like this:
def index
## other code ##
response = HTTParty.get("http://localhost:3000/api/v1/products.json")
## other code ##
end
I want pagination done on the server side so i have not installed kaminari on the client. I can choose which page i want by adding page
parameter on the url like this:
response = HTTParty.get("http://localhost:3000/api/v1/products.json?page=3")
and it works. What can i do on either the service side or the client to achieve next page and previous page without installing kaminari on the client.