In memory REST server for mock, prototyping and education purposes.
Build on top of JSON Server and Faker.
The main reason of this project is:
- Add ability to auto generate data with Faker for provided resources.
- Create custom resources
- Limit number of resource items
- Reset data to defaults if this server users post some broken resources data.
- Contain simple websocket 'chat' application.
Default resources:
/todos
/contacts
/stickers
/students
/tables
/waiters
/dishes
/orders
/reset
- reset resources to defaults/chat
- websocket chat app
My own instance of Mock API Server in Google Cloud
npm install
npm run start
By default, it will run http://localhost:4000
Read
GET /todos
GET /todos/1
Create
POST /todos
Update
PUT /todos/1
PATCH /todos/1
Delete
DELETE /todos/1
For more details (filtering, sorting, paginate, slicing, full-text search) see JSON Server Routes
In order to create custom resources or modify existing edit file:
./src/utils/generateMockData.js
Do not forget restart server.
In order to reset data push button Reset to defaults
on main page or just call resource /reset
Embedded this app websocket-server-chat
Local URL
const ws = new WebSocket('ws://localhost:4000/chat');
Example app URL
const ws = new WebSocket('ws://mock-api-5678.nw.r.appspot.com/chat');
Simple client example:
const ws = new WebSocket('ws://localhost:4000/chat');
ws.onopen = () => {
console.log('Connection with server was established')
ws.send('New client connected');
};
ws.onclose = () => {
console.log('Connection with server was closed')
};
ws.onmessage = (event) => {
console.log('received: %s', event.data);
};
ws.onerror = (error) => {
console.log('Error', error);
};
See ./config.js
- PORT (4000 default) - You can change default port in
./config.js
or providingprocess.env.PORT
env variable - RESOURCE_ITEMS_LIMIT (50 default) - The maximum amount of items in every resource, max 50 todos, max 50 contacts, etc.
- WS_CHAT_ROUTE ('/chat' default) - route for websocket chat app
Initialize your SDK
gcloud init
Deploy to App Engine
gcloud app deploy
- Authentication
- Random Errors