Web

[JSON Server] 프론트엔드용 가상 REST API 설치방법

devkmee 2023. 5. 30. 20:10

 

vue.js를 공부하다보니 백엔드를 구축하지않고 DB를 사용할 수 있는 환경이 필요했다.

JSON Server로 일종의 가상 DB를 구현하는 방법을 알게되어 정리한다.

 

 

> 참고용

https://www.npmjs.com/package/json-server

 

json-server

Get a full fake REST API with zero coding in less than 30 seconds. Latest version: 0.17.3, last published: 2 months ago. Start using json-server in your project by running `npm i json-server`. There are 312 other projects in the npm registry using json-ser

www.npmjs.com

 

1. JSON Server 설치

npm install -g json-server

 

2. db.json 생성

{
  "posts": [
    { "id": 1, "title": "json-server", "author": "typicode" }
  ],
  "comments": [
    { "id": 1, "body": "some comment", "postId": 1 }
  ],
  "profile": { "name": "typicode" }
}

db.json  파일을 생성 한 후 db구조를 잡아준다.

posts, comments, profile이 일종의 테이블이고 그 안에 담긴 것이 컬럼과 값이라고 생각하면 된다.

 

 

3. JSON Server 실행

json-server --watch db.json

해당 url로 접속하면