點燈坊

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

Creating Our Own Routes by JSON Server

Sam Xiao's Avatar 2022-12-30

We can create our own routes by JSON Server without any scripts.

Version

JSON Server 0.17.1

Route Mapping

routes.json

{
  "/api/posts": "/posts",
  "/api/posts/:id": "/posts/:id"
}
  • Create route.json under JSON Server folder
  • Map our own routes to original routes

Apply New Route

$ json-server db.json --routes routes.json
  • routes:apply new route to routes.json

Conclusion

  • Just create routes.json to define our own routes