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

serve-json

v1.0.4

Published

A mock server for any kind of JSON file

Downloads

38

Readme

serve-json

A light weight mock server for any kind of JSON file.

This software is released under the MIT License, see LICENSE.txt.

Features

  • Serves all the data in JSON file via api.
  • Light weight.
  • Source code is ultra small. Easy to undarstand and modify.
  • Supports query.
  • Deep nesting.

Installation

Install globally with npm

$ npm i serve-json -g

Getting started

Prepare your JSON file.

A sample file named data.json is prepared for modification in this package.

Start serve-json specifying your JSON file.

$ serve-json data.json
serve-json started listening port: 3000

Explanation

If your JSON file is like this, serve-json automatically serves APIs below.

data.json

{	"jockeys":
	{	"05339":
		{	"name": "Christophe Patrice Lemaire"
		,	"birthday": 19790520
		}
	,	"05212":
		{	"name": "Mirco Demuro"
		,	"birthday": 19790111
		}
	}
,	"races":
	[	{	"date":	20181125
		,	"name": "Japan Cup"
		,	"grade": "G1"
		,	"horses": [ "Almond Eye" ]
		}
	,	{	"date":	20181125
		,	"name": "Keihan Hai"
		,	"grade": "G3"
		,	"horses": [ "Danon Smash" ]
		}
	,	{	"date":	20190120
		,	"name": "Tokai S."
		,	"grade": "G2"
		,	"horses": [ "Inti" ]
		}
	,	{	"date":	20190120
		,	"name": "American Jockey Club Cup"
		,	"grade": "G2"
		,	"horses": [ "Sciacchetra" ]
		}
	]
}

Available APIs

  • for GET, PUT, DELETE
/
/jockeys
/jockeys/05339
/jockeys/05339/name
/jockeys/05339/birthday
/jockeys/05212
/jockeys/05212/name
/jockeys/05212/birthday
/races
/races/0
/races/0/date
/races/0/name
/races/0/grade
/races/0/horses
/races/0/horses/0
/races/1
/races/1/date
/races/1/name
/races/1/grade
/races/1/horses
/races/1/horses/0
/races/2
/races/2/date
/races/2/name
/races/2/grade
/races/2/horses
/races/2/horses/0
/races/3
/races/3/date
/races/3/name
/races/3/grade
/races/3/horses
/races/3/horses/0
  • for POST
/races
/races/0/horses
/races/1/horses
/races/2/horses
/races/3/horses

Sample

Assuming that your serve-json is running on port 3000.

Get all data.

$ curl localhost:3000
{"jockeys":{"05339":{"name":"Christophe Patrice Lemaire","birthday":19790520},"05212":{"name":"Mirco Demuro","birthday":19790111}},"races":[{"date":20181125,"name":"Japan Cup","grade":"G1","horses":["Almond Eye"]},{"date":20181125,"name":"Keihan Hai","grade":"G3","horses":["Danon Smash"]},{"date":20190120,"name":"Tokai S.","grade":"G2","horses":["Inti"]},{"date":20190120,"name":"American Jockey Club Cup","grade":"G2","horses":["Sciacchetra"]}]}

Get some data

$ curl 'localhost:3000/jockeys/05339/birthday'
19790520

Query

$ curl localhost:3000/jockeys?name=Mirco+Demuro
{"05212":{"name":"Mirco Demuro","birthday":19790111}}
$ curl 'localhost:3000/races?date=20181125&grade=G3'
[{"date":20181125,"name":"Keihan Hai","grade":"G3","horses":["Danon Smash"]}]

Post to array

Don't forget to set Content-Type.

$ curl -H "Content-Type: application/json" localhost:3000/races -d '{ "date": 20181228, "name": "Hopeful S.", "grade": "G1", "horses": [ "Saturnalia", "Admire Justa" ] }'
4
$ curl -H "Content-Type: application/json" localhost:3000/races/4/horses -d '"Vin de Garde"'
2

POST returns index where data is pushed.

Put

$ curl -X PUT -H "Content-Type: application/json" localhost:3000/jockeys/05339/birthday -d '0'
19790520
$ curl -X PUT -H "Content-Type: application/json" localhost:3000/jockeys/05339/sex -d '1'
null

PUT returns old data.

Delete

$ curl -X DELETE localhost:3000/jockeys/05212/birthday
19790111

DELETE returns old data.

License

MIT