{"id":21358514,"url":"https://github.com/jsonapi-rb/jsonapi-renderer","last_synced_at":"2025-04-09T14:09:11.458Z","repository":{"id":56879495,"uuid":"71955149","full_name":"jsonapi-rb/jsonapi-renderer","owner":"jsonapi-rb","description":"Efficiently render JSON API documents.","archived":false,"fork":false,"pushed_at":"2023-08-31T15:08:03.000Z","size":49,"stargazers_count":30,"open_issues_count":11,"forks_count":12,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-03-31T15:08:09.911Z","etag":null,"topics":["api","json","json-api","jsonapi","jsonapi-rb","serialization"],"latest_commit_sha":null,"homepage":"http://jsonapi-rb.org","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/jsonapi-rb.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-10-26T01:47:48.000Z","updated_at":"2025-03-17T06:41:27.000Z","dependencies_parsed_at":"2024-06-18T17:10:58.769Z","dependency_job_id":null,"html_url":"https://github.com/jsonapi-rb/jsonapi-renderer","commit_stats":{"total_commits":42,"total_committers":6,"mean_commits":7.0,"dds":0.1428571428571429,"last_synced_commit":"92e2d1f38930a80b9692d73fa8b3798f7fbac50e"},"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jsonapi-rb%2Fjsonapi-renderer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jsonapi-rb%2Fjsonapi-renderer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jsonapi-rb%2Fjsonapi-renderer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jsonapi-rb%2Fjsonapi-renderer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jsonapi-rb","download_url":"https://codeload.github.com/jsonapi-rb/jsonapi-renderer/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247229290,"owners_count":20905020,"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":["api","json","json-api","jsonapi","jsonapi-rb","serialization"],"created_at":"2024-11-22T05:18:17.440Z","updated_at":"2025-04-09T14:09:11.442Z","avatar_url":"https://github.com/jsonapi-rb.png","language":"Ruby","readme":"# jsonapi-renderer\nRuby gem for rendering [JSON API](http://jsonapi.org) documents.\n\n## Status\n\n[![Gem Version](https://badge.fury.io/rb/jsonapi-renderer.svg)](https://badge.fury.io/rb/jsonapi-renderer)\n[![Build Status](https://secure.travis-ci.org/jsonapi-rb/jsonapi-renderer.svg?branch=master)](http://travis-ci.org/jsonapi-rb/renderer?branch=master)\n[![codecov](https://codecov.io/gh/jsonapi-rb/jsonapi-renderer/branch/master/graph/badge.svg)](https://codecov.io/gh/jsonapi-rb/renderer)\n[![Gitter chat](https://badges.gitter.im/gitterHQ/gitter.png)](https://gitter.im/jsonapi-rb/Lobby)\n\n## Resources\n\n* Chat: [gitter](http://gitter.im/jsonapi-rb)\n* Twitter: [@jsonapirb](http://twitter.com/jsonapirb)\n* Docs: [jsonapi-rb.org](http://jsonapi-rb.org)\n\n## Installation\n```ruby\n# In Gemfile\ngem 'jsonapi-renderer'\n```\nthen\n```\n$ bundle\n```\nor manually via\n```\n$ gem install jsonapi-renderer\n```\n\n## Usage\n\nFirst, require the gem:\n```ruby\nrequire 'jsonapi/renderer'\n```\n\n### Rendering resources\n\nA resource here is any class that implements the following interface:\n```ruby\nclass ResourceInterface\n  # Returns the type of the resource.\n  # @return [String]\n  def jsonapi_type; end\n\n  # Returns the id of the resource.\n  # @return [String]\n  def jsonapi_id; end\n\n  # Returns a hash containing, for each included relationship, an array of the\n  # resources to be included from that one.\n  # @param included_relationships [Array\u003cSymbol\u003e] The keys of the relationships\n  #   to be included.\n  # @return [Hash{Symbol =\u003e Array\u003c#ResourceInterface\u003e}]\n  def jsonapi_related(included_relationships); end\n\n  # Returns a JSON API-compliant representation of the resource as a hash.\n  # @param options [Hash]\n  #   @option fields [Set\u003cSymbol\u003e, Nil] The requested fields, or nil.\n  #   @option include [Set\u003cSymbol\u003e] The requested relationships to\n  #     include (defaults to []).\n  # @return [Hash]\n  def as_jsonapi(options = {}); end\nend\n```\n\n#### Rendering a single resource\n```ruby\nJSONAPI.render(data: resource,\n               include: include_string,\n               fields: fields_hash,\n               meta: meta_hash,\n               links: links_hash)\n```\n\nThis returns a JSON API compliant hash representing the described document.\n\n#### Rendering a collection of resources\n```ruby\nJSONAPI.render(data: resources,\n               include: include_string,\n               fields: fields_hash,\n               meta: meta_hash,\n               links: links_hash)\n```\n\nThis returns a JSON API compliant hash representing the described document.\n\n#### Rendering a relationship\n```ruby\nJSONAPI.render(data: resource,\n               relationship: :posts,\n               include: include_string,\n               fields: fields_hash,\n               meta: meta_hash,\n               links: links_hash)\n```\n\nThis returns a JSON API compliant hash representing the described document.\n\n### Rendering errors\n\n```ruby\nJSONAPI.render_errors(errors: errors,\n                      meta: meta_hash,\n                      links: links_hash)\n```\n\nwhere `errors` is an array of objects implementing the `as_jsonapi` method, that\nreturns a JSON API-compliant representation of the error.\n\nThis returns a JSON API compliant hash representing the described document.\n\n### Caching\n\nThe generated JSON fragments can be cached in any cache implementation\nsupporting the `fetch_multi` method.\n\nWhen using caching, the serializable resources must implement an\nadditional `jsonapi_cache_key` method:\n```ruby\n  # Returns a cache key for the resource, parameterized by the `include` and\n  #   `fields` options.\n  # @param options [Hash]\n  #   @option fields [Set\u003cSymbol\u003e, Nil] The requested fields, or nil.\n  #   @option include [Set\u003cSymbol\u003e] The requested relationships to\n  #     include (defaults to []).\n  # @return [String]\n  def jsonapi_cache_key(options = {}); end\n```\n\nThe cache instance must be passed to the renderer as follows:\n```ruby\nJSONAPI.render(data: resources,\n               include: include_string,\n               fields: fields_hash,\n               cache: cache_instance)\n```\n\n## License\n\njsonapi-renderer is released under the [MIT License](http://www.opensource.org/licenses/MIT).\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjsonapi-rb%2Fjsonapi-renderer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjsonapi-rb%2Fjsonapi-renderer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjsonapi-rb%2Fjsonapi-renderer/lists"}