json server

Lipton·2021년 10월 31일
0

설치하기
npm install -g json-server

.json 파일 만들기

data.json 안에 gameTime과 hotGroup 데이터 만들었음

실행하기
json-server --watch 파일경로/파일이름.json --port 4000
ex) json-server --watch ./data.json --port 4000

불러오기

import axios from 'axios';

export const getPosts = async () => {
  const response = await axios.get('http://localhost:4000/데이터이름(ex:gameTime');
  return response.data;
};

export const getPostById = async id => {
  const response = await axios.get(`http://localhost:4000/posts/${id}`);
  return response.data;
};

참고
https://react.vlpt.us/redux-middleware/08-json-server.html

profile
Web Frontend

0개의 댓글

관련 채용 정보