https://github.com/AlchemyCMS/alchemy-json_api
A JSON:API compliant API for AlchemyCMS
https://github.com/AlchemyCMS/alchemy-json_api
alchemy jsonapi
Last synced: 6 months ago
JSON representation
A JSON:API compliant API for AlchemyCMS
- Host: GitHub
- URL: https://github.com/AlchemyCMS/alchemy-json_api
- Owner: AlchemyCMS
- License: bsd-3-clause
- Created: 2020-04-24T12:28:19.000Z (almost 6 years ago)
- Default Branch: main
- Last Pushed: 2024-11-15T12:04:47.000Z (about 1 year ago)
- Last Synced: 2024-11-15T12:34:57.486Z (about 1 year ago)
- Topics: alchemy, jsonapi
- Language: Ruby
- Homepage:
- Size: 487 KB
- Stars: 6
- Watchers: 6
- Forks: 6
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this 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:
```ruby
gem 'alchemy-json_api'
```
And then execute:
```bash
$ bundle
```
Or install it yourself as:
```bash
$ gem install alchemy-json_api
```
### In your JS/Frontend app
Run this in your application:
```
npm install @alchemy_cms/json_api --save
```
or with the package manager of your choice
## Usage
### In your Rails app
Mount the engine in your Alchemy Rails app like this:
```rb
# 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.
```js
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
```rb
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](https://opensource.org/licenses/BSD-3-Clause).