{"id":28756435,"url":"https://github.com/evalmee/json_api_filter","last_synced_at":"2026-04-01T21:01:52.804Z","repository":{"id":40011386,"uuid":"222764787","full_name":"evalmee/json_api_filter","owner":"evalmee","description":"Filter for rails controller based on JsonAPI spec","archived":false,"fork":false,"pushed_at":"2023-03-08T22:43:01.000Z","size":90,"stargazers_count":3,"open_issues_count":6,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2026-01-13T06:59:11.227Z","etag":null,"topics":["jsonapi","rails","ruby"],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/evalmee.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2019-11-19T18:41:39.000Z","updated_at":"2022-08-29T12:14:18.000Z","dependencies_parsed_at":"2023-07-21T21:53:55.453Z","dependency_job_id":null,"html_url":"https://github.com/evalmee/json_api_filter","commit_stats":{"total_commits":57,"total_committers":5,"mean_commits":11.4,"dds":0.4736842105263158,"last_synced_commit":"e6d30cc3f088dba5459796bbc467e74d695b7216"},"previous_names":["blaked84/json_api_filter"],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/evalmee/json_api_filter","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/evalmee%2Fjson_api_filter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/evalmee%2Fjson_api_filter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/evalmee%2Fjson_api_filter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/evalmee%2Fjson_api_filter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/evalmee","download_url":"https://codeload.github.com/evalmee/json_api_filter/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/evalmee%2Fjson_api_filter/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31014145,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-27T02:58:54.984Z","status":"ssl_error","status_checked_at":"2026-03-27T02:58:46.993Z","response_time":164,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["jsonapi","rails","ruby"],"created_at":"2025-06-17T03:07:29.520Z","updated_at":"2026-03-27T03:24:49.389Z","avatar_url":"https://github.com/evalmee.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# JsonApiFilter\n\nFilter for rails controller based on JsonAPI spec: `/books?filter[library_id]=1,2\u0026filter[author_id][eq]=12\u0026filter[created_at][gt]=2021-02-02`\n\n[![Maintainability](https://api.codeclimate.com/v1/badges/92a4a44d4af2bfa3b27d/maintainability)](https://codeclimate.com/github/evalmee/json_api_filter/maintainability)\n[![Gem Version](https://badge.fury.io/rb/json_api_filter.svg)](https://badge.fury.io/rb/json_api_filter)\n[![Build Status](https://travis-ci.com/evalmee/json_api_filter.svg?branch=master)](https://travis-ci.com/evalmee/json_api_filter)\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n```ruby\ngem 'json_api_filter'\n```\n\nAnd then execute:\n```bash\n$ bundle\n```\n\nOr install it yourself as:\n```bash\n$ gem install json_api_filter\n```\n\n## Usage\n\n### Quick start\n\nTo filter this request `/books?filter[library_id]=1,2\u0026filter[author_id]=12\u0026search=Lord of the ring\u0026include=users,users.posts`\n\n```ruby\nclass Book \u003c ApplicationController\n\n  include JsonApiFilter\n  permitted_filters  %i[library_id author_id]\n  permitted_searches :user_search\n  permitted_inclusions %i[users users.posts]\n\n  def index\n    @books = json_api_filter(Book, params)\n    inclusions = json_api_inclusions(params) # returns [:users, :'users.posts']\n\n    # then use `inclusions` in the serialiser\n    BookSerializer.new(@books, include: inclusions).serializable_hash.to_json\n  end\nend\n\n```\n\n- `permitted_filters` let you define allowed attributes to filter on (mandatory)\n- `permitted_searches` let you define the allowed search method defined in you model what will be called if you pass `search` params in your request (can be a pg_search scope)\n- `permitted_inclusions` let you define the allowed inclusions\n- `json_api_filter(scope, params)` return an active record relation (`Book::` in this example)\n\n# Use inclusions in serializers\n\n# Handling errors\n\nIf an endpoint does not support the include parameter, it MUST respond with 400 Bad Request to any requests that include it.\n\n```ruby\nclass Book \u003c ApplicationController\n\n  include JsonApiFilter\n  permitted_filters  %i[library_id author_id]\n  permitted_searches :user_search\n  \n  rescue_from JsonApiFilter::MissingPermittedInclusionError, with: :render_400\n\n  def index\n    @books = json_api_filter(Book, params)\n    inclusions = json_api_inclusions(params) # raises JsonApiFilter::MissingPermittedInclusionError\n  end\n  \n  private\n  \n  def render_400(exception)\n    render json: exception, status: 400\n  end\nend\n```\n\nIf a server is unable to identify a relationship path or does not support inclusion of resources from a path, it MUST respond with 400 Bad Request.\nThis request should return a 400 status:\n\n `/books?filter[library_id]=1,2\u0026filter[author_id]=12\u0026search=Lord of the ring\u0026include=users,users.posts, users.addresses`\n\n```ruby\nclass Book \u003c ApplicationController\n\n  include JsonApiFilter\n  permitted_filters  %i[library_id author_id]\n  permitted_searches :user_search\n  permitted_inclusions %i[users users.posts]\n\n  rescue_from JsonApiFilter::UnknownInclusionsError, with: :render_400\n\n  def index\n    @books = json_api_filter(Book, params)\n    inclusions = json_api_inclusions(params) # raises JsonApiFilter::UnknownInclusionsError\n  end\n\n  private\n\n  def render_400(exception)\n    render json: exception, status: 400\n  end\nend\n```\n\n## Migration from 0.1\n0.2.x version is not compatible with 0.1\nIn your controller, you will have to replace all occurrences of `attr_filter` as bellow :\n\n### Before\n```ruby\ndef index \n  @books = Book.all.where(attr_filter(params))\nend\n```\n\n### After\n```ruby\ndef index\n  @books = json_api_filter(Book, params)\nend\n```\n\n## Development\n\nAfter checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.\n\nTo install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).\n\n## Contributing\n\nBug reports and pull requests are welcome on GitHub at https://github.com/Blaked84/json_api_filter. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.\n\n## License\n\nThe gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).\n\n## Code of Conduct\n\nEveryone interacting in the JsonApiFilter project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/Blaked84/json_api_filter/blob/master/CODE_OF_CONDUCT.md).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fevalmee%2Fjson_api_filter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fevalmee%2Fjson_api_filter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fevalmee%2Fjson_api_filter/lists"}