{"id":25254224,"url":"https://github.com/alchemycms/alchemy-json_api","last_synced_at":"2025-10-27T01:30:58.321Z","repository":{"id":42680451,"uuid":"258506292","full_name":"AlchemyCMS/alchemy-json_api","owner":"AlchemyCMS","description":"A JSON:API compliant API for AlchemyCMS","archived":false,"fork":false,"pushed_at":"2025-01-21T20:48:01.000Z","size":509,"stargazers_count":6,"open_issues_count":3,"forks_count":6,"subscribers_count":6,"default_branch":"main","last_synced_at":"2025-01-21T21:32:35.291Z","etag":null,"topics":["alchemy","jsonapi"],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/AlchemyCMS.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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":"2020-04-24T12:28:19.000Z","updated_at":"2025-01-09T15:51:03.000Z","dependencies_parsed_at":"2024-01-13T20:56:29.551Z","dependency_job_id":"2636e773-cc3c-4db1-a63e-15891e507b94","html_url":"https://github.com/AlchemyCMS/alchemy-json_api","commit_stats":null,"previous_names":[],"tags_count":42,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AlchemyCMS%2Falchemy-json_api","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AlchemyCMS%2Falchemy-json_api/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AlchemyCMS%2Falchemy-json_api/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AlchemyCMS%2Falchemy-json_api/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/AlchemyCMS","download_url":"https://codeload.github.com/AlchemyCMS/alchemy-json_api/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":238418211,"owners_count":19468865,"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":["alchemy","jsonapi"],"created_at":"2025-02-12T05:31:21.661Z","updated_at":"2025-10-27T01:30:58.316Z","avatar_url":"https://github.com/AlchemyCMS.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Alchemy::JsonApi\n\nA JSON-API based API for AlchemyCMS\n\n## Installation\n\n### In your Alchemy Rails project\n\nAdd this line to your application's Gemfile:\n\n```ruby\ngem 'alchemy-json_api'\n```\n\nAnd then execute:\n\n```bash\n$ bundle\n```\n\nOr install it yourself as:\n\n```bash\n$ gem install alchemy-json_api\n```\n\n### In your JS/Frontend app\n\nRun this in your application:\n\n```\nnpm install @alchemy_cms/json_api --save\n```\n\nor with the package manager of your choice\n\n## Usage\n\n### In your Rails app\n\nMount the engine in your Alchemy Rails app like this:\n\n```rb\n# config/routes.rb\nmount Alchemy::JsonApi::Engine =\u003e \"/jsonapi/\"\n```\n\n\u003e __NOTE__ Pick any path you like. This will be the **prefix** of your API URLs\n\n### In your frontend app\n\nThis repo provides an NPM package with deserializers to help you convert the response into JS objects.\n\n```js\nimport { deserializePages } from \"@alchemy_cms/json_api\"\n\nconst response = await fetch(\"/jsonapi/pages.json\")\nconst data = await response.json()\nconst pages = deserializePages(data)\n\nconsole.log(pages[0].name) // =\u003e Homepage\n```\n\n## HTTP Caching\n\nAlchemy::JsonApi allows for caching API responses. It respects the caching configuration of your Rails app and of your Alchemy configuration and settings in the pages page layout configuration. Restricted pages are never cached.\n\nBy default it sets the `max-age` `Cache-Control` header to 10 minutes (`600` seconds). You can change this by configuring the `Alchemy::JsonApi.page_cache_max_age` setting. It is recommended to set this via an environment variable like this:\n\n```rb\n# config/initializers/alchemy_json_api.rb\nAlchemy::JsonApi.page_cache_max_age = ENV.fetch(\"ALCHEMY_JSON_API_CACHE_DURATION\", 600).to_i\n```\n\n### Edge Caching\n\nAlchemy sets the `must-revalidate` directive if caching is enabled. If your CDN supports it, you can change that to use the much more efficient `stale-while-revalidate` directive by changing the `Alchemy::JsonApi.page_caching_options` setting to any integer value.\n\n```rb\n# config/initializers/alchemy_json_api.rb\nAlchemy::JsonApi.page_caching_options = {\n  stale_while_revalidate: ENV.fetch(\"ALCHEMY_JSON_API_CACHE_STALE_WHILE_REVALIDATE\", 60).to_i\n}\n```\n\n\u003e [!TIP]\n\u003e You can set any caching option that [`ActionController::ConditionalGet#expires_in` supports](https://api.rubyonrails.org/classes/ActionController/ConditionalGet.html#method-i-expires_in), like `stale_if_error`, `public` or `immutable`.\n\n## Key transforms\n\nIf you ever want to change how Alchemy serializes attributes you can set\n\n```rb\n# config/initializers/alchemy_json_api.rb\nAlchemy::JsonApi.key_transform = :camel_lower\n```\n\nIt defaults to `:underscore`.\n\n## Contributing\n\nContribution directions go here.\n\n## License\n\nThe gem is available as open source under the terms of the [BSD-3-Clause license](https://opensource.org/licenses/BSD-3-Clause).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falchemycms%2Falchemy-json_api","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falchemycms%2Falchemy-json_api","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falchemycms%2Falchemy-json_api/lists"}