0.01
The project is in a healthy, maintained state
A JSONAPI compliant API for AlchemyCMS
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

Runtime

>= 1.6.0, < 2.1
>= 7.0.0.a, < 8
 Project Readme

Alchemy::JsonApi

A JSON-API based API for AlchemyCMS

Installation

In your Alchemy Rails project

Add this line to your application's Gemfile:

gem 'alchemy-json_api'

And then execute:

$ bundle

Or install it yourself as:

$ gem install alchemy-json_api

In your JS/Frontend app

Run this in your application:

yarn add "@alchemy_cms/json_api"

Usage

In your Rails app

Mount the engine in your Alchemy Rails app like this:

# config/routes.rb
mount Alchemy::JsonApi::Engine => "/jsonapi/"

NOTE Pick any path you like. This will be the prefix of your API URLs

In your frontend app

This repo provides an NPM package with deserializers to help you convert the response into JS objects.

import { deserializePages } from "@alchemy_cms/json_api"

const response = await fetch("/jsonapi/pages.json")
const data = await response.json()
const pages = deserializePages(data)

console.log(pages[0].name) // => Homepage

Key transforms

If you ever want to change how Alchemy serializes attributes you can set

Alchemy::JsonApi.key_transform = :camel_lower

It defaults to :underscore.

Contributing

Contribution directions go here.

License

The gem is available as open source under the terms of the BSD-3-Clause license.