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 🙏

© 2024 – Pkg Stats / Ryan Hefner

git-json-api

v3.2.1

Published

A JSON API to serve the contents of JSON files from a Git repo. All files in the repo are expected to be JSON files with a `.json` extension.

Downloads

6

Readme

Git JSON API

A JSON API to serve the contents of JSON files from a Git repo. All files in the repo are expected to be JSON files with a .json extension.

Configuration

Environment Variables

The service uses the following environment variables:

  • REPO_URI (required) URI of the Git repository
  • SIGNATURE_MAIL (optional) E-mail address used for generated commits
  • REPO_TOKEN (optional) Token for accessing private repo
  • GIT_JSON_API_VAR_*(optional) A list of variables to be replaced in the content (see "Variable Replacement" for details)

Variable Replacement

The service replaces variables in files when serving and writing. All variables need to be environment variables prefixed with GIT_JSON_API_VAR_. Example:

export GIT_JSON_API_VAR_MY_FANCY_VARIABLE="value"

If a variable occurs in the content it will be replaced by the given value. When writing to the repo values will also be replaced by their variable name.

Example

Content:                          "Hello ${properGreeting}."  
GIT_JSON_API_VAR_PROPER_GREETING: "World"  
Served:                           "Hello World."

API

GET /:version

Returns the contents of the repo at the given version as a single JSON object.

Version can either be a Git commit hash or a reference. The response will contain the Git commit hash in the Git-Commit-Hash header.

The returned object contains the contents of every file in the root of the repo in a property named like the file (without extension). For every directory, it contains another object with the same structure.

If a repo contains file1.json, file2.json, directory/fileA.json and directory/subDirectory/fileB.json, the response would be structured as follows:

// GET <url>/master
{
  "directory" : {
    "fileA": {
      "foo": "bar"
    },
    "subDirectory": {
      "fileB": {
        "foo": "bar"
      }
    }
  },
  "file1": {
    "min": 1,
    "max": 10
  },
  "file2": [
    "item1",
    "item2",
    "item3"
  ]
}

GET /:version/path

Optionally, the previous route can be called with an additional path into the content to retrieve specific data.

// GET <url>/master/directory/fileA
{
  "foo": "bar"
}

PUT /:version/path

The content of a directory or single file can be replaced using a PUT request. The body is expected to contain JSON data for all files and subdirectories or a file. The intended workflow is to query a path using GET /:version/path, make the desired changes to the data and send the whole data back via PUT /:parentVersion/path.

A new Git commit will be created and merged if necessary. The response will contain the hash of the new (merge) commit in the Git-Commit-Hash header. If the merge fails, an error will be returned.

Examples

The body to replace everything inside directory looks like this:

// PUT <url>/master/directory
{
  "files": {
    "fileA": {
      "foo": "bar"
    },
    "subDirectory/fileB": {
        "foo": "bar"
      }
    }
  }
}

The body to replace a single file only looks like this:

// PUT <url>/master/file1
{
  "fileContent" : {
    "min": 10,
    "max": 30
  }
}

Additional properties are:
author: Will be used as commit author.
updateBranch: The branch which should be updated to the new commit (default: "master").

Development Setup

npm install
REPO_URI=<repo-url> npm run watch

Deployment

Heroku/Dokku

The service is designed to be deployed using Dokku and will probably also work with Heroku and other compatible platforms.

Dockerfile

The service contains a Dockerfile to start it directly with Docker.