點燈坊

失くすものさえない今が強くなるチャンスよ

Simulating Query String Style API by JSON Server

Sam Xiao's Avatar 2022-12-31

Some API uses query string style, Can we use JSON Server to support query string style API ?

Version

JSON Server 0.17.1

Add Route

routes.json

{
  "/api/posts": "/posts",
  "/api/posts?id=:id": "/posts/:id"
}

JSON Server only supports URI style API, we have to define query string style API mapping on routes.json

Apply New Route

$ json-server db.json --routes routes.json
  • Start JSON Server by db.json database file and routes.json route file

Conclusion

  • By simple route file, we can simulate query string style API by JSON Server