diff --git a/README.md b/README.md index 1de6beb..9393c6f 100644 --- a/README.md +++ b/README.md @@ -224,7 +224,7 @@ defaults to the results of your `records/1` callback). For example, given the following request: -`GET /v1/articles?filter[category]=dogs&sort=-published` +`GET /v1/articles?filter[category]=dogs&filter[favourite-snack]=cheese&sort=-published` You would implement the following callbacks: @@ -236,6 +236,10 @@ defmodule MyApp.ArticleController do def filter(_conn, query, "category", category) do where(query, category: ^category) end + + def filter(_conn, query, "favourite_snack", snack) do + where(query, favourite_snack: ^favourite_snack) + en def sort(_conn, query, "published", direction) do order_by(query, [{^direction, :inserted_at}]) @@ -243,6 +247,8 @@ defmodule MyApp.ArticleController do end ``` +Note that in the case of `filter[favourite-snack]` JaResource has already helpfully converted the filter param's name from dasherized to underscore (or from [whatever you configured](https://github.com/vt-elixir/ja_serializer#key-format-for-attribute-relationship-and-query-param) your API to use). + ### Paginate The handle_index_query/2 can be used to apply query params and render_index/3 to serialize meta tag.