From 56e6660b123b29735562b1ac1aac7445211dbaca Mon Sep 17 00:00:00 2001 From: Michael Pepping Date: Thu, 23 Dec 2021 09:33:12 +1000 Subject: [PATCH] adds query parameters section to README.md --- README.md | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/README.md b/README.md index 4969347..95bcfed 100644 --- a/README.md +++ b/README.md @@ -124,6 +124,32 @@ resource = CommentResource.new(connection: conn, scope: user) comments = resource.all #=> Will fetch from /users/123/comments ``` +## Query Parameters + +Sometimes you may want to send additional query parameters with your requests that are not part of the path. +To do this, you will need to tell the action which parameters it is allowed to accept and send using the `query_key` method. + +Any parameters that are not listed will not be sent. + +For example, you may want to send a page number and the number of posts per page when requesting a list of Posts: + +```ruby +class PostResource < ResourceKit::Resource + resources do + action :all do + verb :get + path { "/posts" } + query_keys :page, :posts_per_page + handler(200) { |resp| PostMapping.extract_collection(resp.body, :read) } + end + end +end + +user = User.find(123) +resource = CommentResource.new(connection: conn, scope: user) +comments = resource.all(page: 10, posts_per_page: 20) #=> Will fetch from /posts?page=10&posts_per_page=20 +``` + ## Test Helpers ResourceKit supplys test helpers that assist in certain things you'd want your resource classes to do.