{"id":19177842,"url":"https://github.com/trailblazer/roar-jsonapi","last_synced_at":"2025-08-20T20:32:42.600Z","repository":{"id":56892461,"uuid":"76124231","full_name":"trailblazer/roar-jsonapi","owner":"trailblazer","description":"JSON API support for Roar.","archived":false,"fork":false,"pushed_at":"2023-01-25T15:09:09.000Z","size":148,"stargazers_count":43,"open_issues_count":13,"forks_count":17,"subscribers_count":11,"default_branch":"master","last_synced_at":"2025-07-07T13:41:46.819Z","etag":null,"topics":["hypermedia","json-api","rest","ruby"],"latest_commit_sha":null,"homepage":"http://trailblazer.to/gems/roar/jsonapi.html","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/trailblazer.png","metadata":{"files":{"readme":"README.markdown","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-12-10T16:29:40.000Z","updated_at":"2025-03-30T18:47:44.000Z","dependencies_parsed_at":"2023-01-27T21:01:32.154Z","dependency_job_id":null,"html_url":"https://github.com/trailblazer/roar-jsonapi","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/trailblazer/roar-jsonapi","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/trailblazer%2Froar-jsonapi","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/trailblazer%2Froar-jsonapi/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/trailblazer%2Froar-jsonapi/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/trailblazer%2Froar-jsonapi/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/trailblazer","download_url":"https://codeload.github.com/trailblazer/roar-jsonapi/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/trailblazer%2Froar-jsonapi/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":270885444,"owners_count":24662455,"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","status":"online","status_checked_at":"2025-08-17T02:00:09.016Z","response_time":129,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":["hypermedia","json-api","rest","ruby"],"created_at":"2024-11-09T10:35:27.109Z","updated_at":"2025-08-20T20:32:42.284Z","avatar_url":"https://github.com/trailblazer.png","language":"Ruby","readme":"# Roar JSON API\n\n_Resource-Oriented Architectures in Ruby._\n\n[![Gitter Chat](https://badges.gitter.im/trailblazer/chat.svg)](https://gitter.im/trailblazer/chat)\n[![TRB Newsletter](https://img.shields.io/badge/TRB-newsletter-lightgrey.svg)](http://trailblazer.to/newsletter/)\n![.github/workflows/tests.yml](https://github.com/trailblazer/roar-jsonapi/workflows/.github/workflows/tests.yml/badge.svg)\n[![Gem Version](https://badge.fury.io/rb/roar-jsonapi.svg)](http://badge.fury.io/rb/roar-jsonapi)\n\nRoar JSON API provides support for [JSON API](http://jsonapi.org/), a specification for building APIs in JSON. It can render _and_ parse singular and collection documents.\n\n### Resource\n\nA minimal representation of a Resource can be defined as follows:\n\n```ruby\nrequire 'roar/json/json_api'\n\nclass SongsRepresenter \u003c Roar::Decorator\n  include Roar::JSON::JSONAPI.resource :songs\n\n  attributes do\n    property :title\n  end\nend\n```\n\nProperties (or attributes) of the represented model are defined within an\n`attributes` block.\n\nAn `id` property will automatically defined when using Roar JSON API.\n\n### Relationships\n\nTo define relationships, use `::has_one` or `::has_many` with either an inline\nor a standalone representer (specified with the `extend:` or `decorates:` option).\n\n```ruby\nclass SongsRepresenter \u003c Roar::Decorator\n  include Roar::JSON::JSONAPI.resource :songs\n\n  has_one :album do\n    property :title\n  end\n\n  has_many :musicians, extend: MusicianRepresenter\nend\n```\n\n### Meta information\n\nMeta information can be included into rendered singular and collection documents in two ways.\n\nYou can define meta information on your collection object and then let Roar compile it.\n\n```ruby\nclass SongsRepresenter \u003c Roar::Decorator\n  include Roar::JSON::JSONAPI.resource :songs\n\n  meta toplevel: true do\n    property :page\n    property :total\n  end\nend\n```\n\nYour collection object must expose the respective methods.\n\n```ruby\ncollection.page  #=\u003e 1\ncollection.total #=\u003e 12\n```\n\nThis will render the `{\"meta\": {\"page\": 1, \"total\": 12}}` hash into the JSON API document.\n\nAlternatively, you can provide meta information as a hash when rendering.  Any values also defined on your object will be overriden.\n\n```ruby\ncollection.to_json(meta: {page: params[\"page\"], total: collection.size})\n```\n\nBoth methods work for singular documents too.\n\n```ruby\nclass SongsRepresenter \u003c Roar::Decorator\n  include Roar::JSON::JSONAPI.resource :songs\n\n  meta do\n    property :label\n    property :format\n  end\nend\n```\n\n```ruby\nsong.to_json(meta: { label: 'EMI' })\n```\n\nIf you need more functionality (and parsing), please let us know.\n\n### Usage\n\nAs JSON API per definition can represent singular models and collections you have two entry points.\n\n```ruby\nSongsRepresenter.prepare(Song.find(1)).to_json\nSongsRepresenter.prepare(Song.new).from_json(\"..\")\n```\n\nSingular models can use the representer module directly.\n\n```ruby\nSongsRepresenter.for_collection.prepare([Song.find(1), Song.find(2)]).to_json\nSongsRepresenter.for_collection.prepare([Song.new, Song.new]).from_json(\"..\")\n```\n\n\nParsing currently works great with singular documents - for collections, we are still working out how to encode the application semantics. Feel free to help.\n\n## Support\n\nQuestions? Need help? Free 1st Level Support on irc.freenode.org#roar !\nWe also have a [mailing list](https://groups.google.com/forum/?fromgroups#!forum/roar-talk), yiha!\n\n## License\n\nRoar 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%2Ftrailblazer%2Froar-jsonapi","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftrailblazer%2Froar-jsonapi","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftrailblazer%2Froar-jsonapi/lists"}