npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@alchemy_cms/json_api

v3.0.1

Published

JSON API deserializer for AlchemyCMS

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:

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:

# 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

HTTP Caching

Alchemy::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.

By 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:

# config/initializers/alchemy_json_api.rb
Alchemy::JsonApi.page_cache_max_age = ENV.fetch("ALCHEMY_JSON_API_CACHE_DURATION", 600).to_i

Edge Caching

Alchemy 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.

# config/initializers/alchemy_json_api.rb
Alchemy::JsonApi.page_caching_options = {
  stale_while_revalidate: ENV.fetch("ALCHEMY_JSON_API_CACHE_STALE_WHILE_REVALIDATE", 60).to_i
}

[!TIP] You can set any caching option that ActionController::ConditionalGet#expires_in supports, like stale_if_error, public or immutable.

Key transforms

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

# config/initializers/alchemy_json_api.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.