# FakeDB
Vuexy is built using FakeDB to mock the real life application functionalities.
# Overview
Vuexy uses axios-mock-adapter (opens new window) to simulate the server calls.
All of the server calls are located in src/@fake-db
.
# Setup
If you're using the starter-kit you'll have to manually setup the fake-db.
First create a folder with name
fake-db
and create amock.ts
file inside it.Initialize the axios-mock-adapter in
mock.ts
file.import axios from 'axios' import MockAdapter from 'axios-mock-adapter' const mock = new MockAdapter(axios) export default mock
Create a
index.ts
file infake-db
folder & add the following:import mock from './mock' mock.onAny().passThrough()
To initialize your fake data create a ts file in
fake-db
folder. Importmock
and use it like following:import mock from '../mock' const data = [{...}] mock.onGet('/url/get-data').reply(config => { return [200, data] })
Import the above created file in
fake-db/index.ts
:import mock from './mock' import './FILE_WITH_DATA' mock.onAny().passThrough()
Import your
fake-db/index.ts
insrc/pages/_app_.ts
to be able to get your data in your app.Finally, use axios to fetch your data from fake-db
import { useState, useEffect } from 'react'
import axios from 'axios'
const Component = () => {
const [data, setData] = useState([])
useEffect(() => {
axios.get('/url/get-data').then(response => setData(response.data))
}, [])
return <h1>Component</h1>
}
WARNING
We have used the fake-db for demo purposes only. fake-db will not work for the real life applications.
← Redux Authentication →