{"id":16679692,"url":"https://github.com/buren/jsonapi_helpers","last_synced_at":"2025-04-09T22:32:42.366Z","repository":{"id":56879487,"uuid":"105301300","full_name":"buren/jsonapi_helpers","owner":"buren","description":"JSONAPI Helpers","archived":false,"fork":false,"pushed_at":"2021-11-29T14:53:44.000Z","size":30,"stargazers_count":2,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-22T03:46:30.259Z","etag":null,"topics":["jsonapi","rubygem","serialization"],"latest_commit_sha":null,"homepage":null,"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/buren.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-09-29T17:48:40.000Z","updated_at":"2017-11-16T21:04:41.000Z","dependencies_parsed_at":"2022-08-20T11:40:42.327Z","dependency_job_id":null,"html_url":"https://github.com/buren/jsonapi_helpers","commit_stats":null,"previous_names":["buren/json_api_helpers"],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/buren%2Fjsonapi_helpers","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/buren%2Fjsonapi_helpers/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/buren%2Fjsonapi_helpers/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/buren%2Fjsonapi_helpers/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/buren","download_url":"https://codeload.github.com/buren/jsonapi_helpers/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247744328,"owners_count":20988784,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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","rubygem","serialization"],"created_at":"2024-10-12T13:36:54.929Z","updated_at":"2025-04-09T22:32:42.343Z","avatar_url":"https://github.com/buren.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# JSONAPIHelpers\n[![Build Status](https://travis-ci.org/buren/jsonapi_helpers.svg?branch=master)](https://travis-ci.org/buren/jsonapi_helpers)\n\nA set of helpers for generating JSON API compliant responses with together with the active_model_serializers gem.\n\n:warning: The API for this is still pretty rough.\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n```ruby\ngem 'jsonapi_helpers'\n```\n\nAnd then execute:\n\n    $ bundle\n\nOr install it yourself as:\n\n    $ gem install jsonapi_helpers\n\n## Usage\n\n:warning: You must configure `deserializer_klass` and `params_klass`, if you want to use the `Dersializer`.\n\n```ruby\nrequire 'jsonapi_helpers'\n\ninclude JSONAPIHelpers::Alias\n\nJSONAPIHelpers.configure do |config|\n  config.deserializer_klass = ActiveModelSerializers::Deserialization\n  config.params_klass = ActionController::Parameters\n  # optional (unaltered is the default)\n  config.key_transform = :dash # camel, camel_lower, underscore, unaltered\nend\n\n# Error\nerrors = JSONAPIHelpers::Serializers::Errors.new\nerrors.add(status: 422, detail: 'too short', attribute: :first_name).to_h\nerrors.to_h\n# =\u003e {\n#   errors: [{\n#     :status =\u003e 422,\n#     :detail =\u003e 'too short',\n#     :source =\u003e {\n#       :pointer =\u003e \"/data/attributes/first-name\"\n#     }\n#   }]\n# }\n\n# In ApplicationController you can define\nclass ApplicationController \u003c ActionController::Base\n  # Define these constants in your controllers that you'd like to have\n  # different/custom behavior\n  DEFAULT_SORTING = { created_at: :desc }.freeze\n  SORTABLE_FIELDS = [].freeze\n\n  ALLOWED_INCLUDES = [].freeze\n\n  TRANSFORMABLE_FILTERS = { created_at: :date_range }.freeze\n  ALLOWED_FILTERS = %i(created_at).freeze\n\n  def jsonapi_params\n    @_deserialized_params ||= JSONAPIHelpers::Serializers::Deserializer.parse(params)\n  end\n\n  def include_params\n    @_include_params ||= JSONAPIHelpers::Params::Includes.new(params[:include])\n  end\n\n  def fields_params\n    @_fields_params ||= JSONAPIHelpers::Params::Fields.new(params[:fields])\n  end\n\n  def sort_params\n    @_sort_params ||= begin\n      sortable_fields = self.class::SORTABLE_FIELDS\n      default_sorting = self.class::DEFAULT_SORTING\n      JSONAPIHelpers::Params::Sort.build(params[:sort], sortable_fields, default_sorting)\n    end\n  end\n\n  def filter_params\n    @_filter_params ||= begin\n      filterable_fields = self.class::ALLOWED_FILTERS\n      transformable = self.class::TRANSFORMABLE_FILTERS\n      JSONAPIHelpers::Params::Filter.build(params[:filter], filterable_fields, transformable)\n    end\n  end\n\n  # ...\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`.\n\n## Future\n\n* Better dependency injection\n* Clean up/normalize the public API\n* Support more of the [JSONAPI](http://jsonapi.org/) standard\n\n## Contributing\n\nBug reports and pull requests are welcome on GitHub at https://github.com/buren/jsonapi_helpers/issues.\n\n## License\n\nThe gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fburen%2Fjsonapi_helpers","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fburen%2Fjsonapi_helpers","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fburen%2Fjsonapi_helpers/lists"}