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

json-file-server

v1.2.3

Published

[![NPM Version](http://img.shields.io/npm/v/json-file-server.svg?style=flat)](https://www.npmjs.org/package/json-file-server)

Downloads

26

Readme

json-file-server

NPM Version

对于前后端完全分离的项目来说,前端只会关心接口,通讯方式一般采用json。所以,理想的状态下就是前端不用直接等待后端完成接口再写逻辑代码,而是直接自己fake一些数据。

参考过json-server,能满足部分需求,然而在实际的上环境比较复杂,以下这2个需求是我迫切需要:

  • 请求一些非RESTFUL API (GET /posts/1.json)
  • URL有后缀 add suffix in url #161
  • fake的数据较大时,比较查看db.json 难以看出其数据结构

个人感觉最理想的情况下是,自己根据URL,构成文件夹,文件目录,编写所需的返回数据

编写mock file(草案)

URL: /path/to/Resource[.suffix|''][.Http_Method][?QueryString|'']

对应文件目录结构:

--...
--path
  --blabla
  --to
    --Resource[.suffix|''][.Http_Method|''][?QueryString|'']
  • Http_Method: Http方法 GET POST PUT DELETE PATCH .....
  • suffix 后缀
    • LangPrefix: 语言占位符 e.g: php, do, aspx
    • ReturnType: 返回类型: e.g: json & xml ,
  • QueryString: QueryString,参数顺序问题值得商讨

Example

Mock File Name|对应请求方法 -----|----- /posts.get | GET /posts /posts.post| POST /posts /posts.json.post | POST /posts.json /post.php.get| GET /post.php /posts/1.get?a=1&b=2 | GET /posts/1?a=1&b=2 /posts/1.json.get?a=1 | GET /posts/1.json?a=1

Getting Start

npm install -g json-file-server
cd path/to/json-file-server # optionals
jfs run -p 3000 .
jfs -help

License

MIT @Jayin Ton