360-mock-server 1.2.5 β 1.2.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +80 -179
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,225 +1,153 @@
|
|
|
1
1
|
# π 360 Mock Server
|
|
2
2
|
|
|
3
|
-
**360 Mock Server** is a zero-
|
|
4
|
-
|
|
3
|
+
**360 Mock Server** is a zero-config mock REST API for frontend developers.
|
|
4
|
+
Create, update, delete, paginate, and auto-generate fake data **without building a backend**.
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
Perfect for **React / React Native / Redux / demos / testing**.
|
|
7
7
|
|
|
8
8
|
|
|
9
|
-
## β¨
|
|
9
|
+
## β¨ Features
|
|
10
10
|
|
|
11
|
-
*
|
|
12
|
-
* Works
|
|
13
|
-
*
|
|
11
|
+
* Zero configuration
|
|
12
|
+
* Works with **any REST endpoint**
|
|
13
|
+
* Full CRUD (GET, POST, PUT, PATCH, DELETE)
|
|
14
|
+
* **Fake data generation (Faker.js)**
|
|
15
|
+
* **Pagination support**
|
|
16
|
+
* Persistent JSON storage
|
|
14
17
|
* Interactive CLI + REST API
|
|
15
|
-
*
|
|
16
|
-
* Ideal for React, React Native, Vue, Angular, Redux apps
|
|
18
|
+
* CORS enabled
|
|
17
19
|
|
|
18
20
|
|
|
19
21
|
## π¦ Installation
|
|
20
22
|
|
|
21
|
-
Install globally using npm:
|
|
22
|
-
|
|
23
23
|
```bash
|
|
24
24
|
npm install -g 360-mock-server
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
Or run directly using `npx` (recommended):
|
|
28
|
-
|
|
29
|
-
```bash
|
|
25
|
+
# or
|
|
30
26
|
npx 360-mock-server
|
|
31
27
|
```
|
|
32
28
|
|
|
33
29
|
|
|
34
|
-
## β‘
|
|
30
|
+
## β‘ Start Server
|
|
35
31
|
|
|
36
32
|
```bash
|
|
37
33
|
npx 360-mock-server
|
|
38
34
|
```
|
|
39
35
|
|
|
40
|
-
|
|
41
|
-
The mock server will start at:
|
|
36
|
+
Server runs at:
|
|
42
37
|
|
|
43
38
|
```
|
|
44
39
|
http://localhost:5050
|
|
45
40
|
```
|
|
46
41
|
|
|
47
42
|
|
|
48
|
-
## π§
|
|
49
|
-
|
|
50
|
-
Once the server starts, you can interact with it directly from the terminal:
|
|
51
|
-
|
|
52
|
-
```text
|
|
53
|
-
360-mock> POST /users {"name": "Ali", "email": "ali@test.com"}
|
|
54
|
-
β
Status: 201
|
|
55
|
-
{"id": 1737745200000, "name": "Ali", "email": "ali@test.com"}
|
|
56
|
-
|
|
57
|
-
360-mock> GET /users
|
|
58
|
-
β
Status: 200
|
|
59
|
-
[{"id": 1737745200000, "name": "Ali", "email": "ali@test.com"}]
|
|
60
|
-
|
|
61
|
-
360-mock> DELETE /users/1737745200000
|
|
62
|
-
β
Status: 200
|
|
63
|
-
```
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
## π CLI Commands (Interactive Mode)
|
|
67
|
-
|
|
68
|
-
| Command | Description |
|
|
69
|
-
| -------------------------------------- | ---------------------------- |
|
|
70
|
-
| `GET /users` | Fetch all users |
|
|
71
|
-
| `GET /users/123` | Fetch user by ID |
|
|
72
|
-
| `POST /users {"name":"Ali"}` | Create a new user |
|
|
73
|
-
| `PUT /users/123 {"name":"New"}` | Replace entire resource |
|
|
74
|
-
| `PATCH /users/123 {"email":"x@y.com"}` | Update specific fields |
|
|
75
|
-
| `DELETE /users/123` | Delete resource |
|
|
76
|
-
| `list` | Show all available resources |
|
|
77
|
-
| `clear` | Clear terminal screen |
|
|
78
|
-
| `help` | Show help |
|
|
79
|
-
| `exit` | Exit interactive mode |
|
|
80
|
-
|
|
81
|
-
## π§ͺ Using with Postman / REST Clients
|
|
82
|
-
|
|
83
|
-
**Base URL**
|
|
43
|
+
## π§ Manual + Faker + Pagination (All-in-One)
|
|
84
44
|
|
|
85
|
-
|
|
86
|
-
http://localhost:5050
|
|
87
|
-
```
|
|
45
|
+
### βΆοΈ Manual CRUD (Normal API)
|
|
88
46
|
|
|
89
|
-
|
|
47
|
+
```bash
|
|
48
|
+
POST /users
|
|
49
|
+
{ "name": "Ali", "email": "ali@test.com" }
|
|
90
50
|
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
| GET | `/users` | β |
|
|
94
|
-
| GET | `/users/123` | β |
|
|
95
|
-
| POST | `/users` | `{ "name": "Ali" }` |
|
|
96
|
-
| PUT | `/users/123` | `{ "name": "Updated" }` |
|
|
97
|
-
| PATCH | `/users/123` | `{ "email": "new@test.com" }` |
|
|
98
|
-
| DELETE | `/users/123` | β |
|
|
51
|
+
GET /users
|
|
52
|
+
GET /users/123
|
|
99
53
|
|
|
100
|
-
|
|
54
|
+
PATCH /users/123
|
|
55
|
+
{ "email": "new@test.com" }
|
|
101
56
|
|
|
102
|
-
|
|
103
|
-
Content-Type: application/json
|
|
57
|
+
DELETE /users/123
|
|
104
58
|
```
|
|
105
59
|
|
|
60
|
+
### π² Faker.js β Auto Generate Fake Data
|
|
106
61
|
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
Generate realistic fake data instantly! Just send a POST request with `fields` array:
|
|
110
|
-
|
|
111
|
-
### Generate 10 Users (default count)
|
|
62
|
+
Just send `fields` array:
|
|
112
63
|
|
|
113
64
|
```bash
|
|
114
65
|
POST /users
|
|
115
66
|
{
|
|
116
|
-
"fields": ["name", "email", "avatar", "phone"]
|
|
67
|
+
"fields": ["name", "email", "avatar", "phone"],
|
|
68
|
+
"count": 10
|
|
117
69
|
}
|
|
118
70
|
```
|
|
119
71
|
|
|
120
|
-
|
|
72
|
+
Works for **any resource**:
|
|
121
73
|
|
|
122
74
|
```bash
|
|
123
75
|
POST /products
|
|
124
76
|
{
|
|
125
|
-
"fields": ["productName", "price", "category"
|
|
126
|
-
"count":
|
|
77
|
+
"fields": ["productName", "price", "category"],
|
|
78
|
+
"count": 20
|
|
127
79
|
}
|
|
128
80
|
```
|
|
129
81
|
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
| Category | Fields |
|
|
133
|
-
| ----------- | ---------------------------------------------------------------------- |
|
|
134
|
-
| **Person** | `name`, `firstName`, `lastName`, `username`, `email`, `phone`, `avatar`, `bio`, `jobTitle`, `gender` |
|
|
135
|
-
| **Location**| `address`, `city`, `state`, `country`, `zipCode`, `latitude`, `longitude` |
|
|
136
|
-
| **Company** | `company`, `companyName`, `department` |
|
|
137
|
-
| **Internet**| `website`, `url`, `ip`, `password` |
|
|
138
|
-
| **Content** | `title`, `description`, `body`, `text`, `sentence`, `paragraph`, `slug`|
|
|
139
|
-
| **Commerce**| `price`, `product`, `productName`, `productDescription`, `category` |
|
|
140
|
-
| **Images** | `image`, `imageUrl` |
|
|
141
|
-
| **Dates** | `date`, `pastDate`, `futureDate`, `birthDate` |
|
|
142
|
-
| **Numbers** | `number`, `age`, `rating`, `quantity` |
|
|
143
|
-
| **Boolean** | `boolean`, `isActive`, `isVerified` |
|
|
144
|
-
| **Misc** | `uuid`, `color`, `word`, `words` |
|
|
145
|
-
|
|
146
|
-
### Get All Available Fields
|
|
82
|
+
Get all supported faker fields:
|
|
147
83
|
|
|
148
84
|
```bash
|
|
149
85
|
GET /faker/fields
|
|
150
86
|
```
|
|
151
87
|
|
|
152
|
-
|
|
88
|
+
### π Pagination (Built-in)
|
|
153
89
|
|
|
90
|
+
```bash
|
|
91
|
+
GET /users?_page=1&_limit=5
|
|
92
|
+
```
|
|
154
93
|
|
|
155
|
-
|
|
94
|
+
Response:
|
|
156
95
|
|
|
157
|
-
|
|
158
|
-
|
|
96
|
+
```json
|
|
97
|
+
{
|
|
98
|
+
"data": [...],
|
|
99
|
+
"pagination": {
|
|
100
|
+
"page": 1,
|
|
101
|
+
"limit": 5,
|
|
102
|
+
"totalItems": 20,
|
|
103
|
+
"totalPages": 4,
|
|
104
|
+
"hasNextPage": true,
|
|
105
|
+
"hasPrevPage": false
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
```
|
|
159
109
|
|
|
160
|
-
|
|
161
|
-
|
|
110
|
+
* Pagination works on **any resource**
|
|
111
|
+
* If `_limit` is missing β returns full array
|
|
162
112
|
|
|
163
|
-
// CREATE
|
|
164
|
-
await fetch(`${API}/users`, {
|
|
165
|
-
method: 'POST',
|
|
166
|
-
headers: { 'Content-Type': 'application/json' },
|
|
167
|
-
body: JSON.stringify({ name: 'Ali', email: 'ali@test.com' })
|
|
168
|
-
});
|
|
169
113
|
|
|
170
|
-
|
|
171
|
-
const users = await fetch(`${API}/users`).then(res => res.json());
|
|
114
|
+
## π» Frontend Usage
|
|
172
115
|
|
|
173
|
-
|
|
174
|
-
await fetch(`${API}/users/123`, {
|
|
175
|
-
method: 'PATCH',
|
|
176
|
-
headers: { 'Content-Type': 'application/json' },
|
|
177
|
-
body: JSON.stringify({ name: 'Updated' })
|
|
178
|
-
});
|
|
116
|
+
### Fetch
|
|
179
117
|
|
|
180
|
-
|
|
181
|
-
|
|
118
|
+
```js
|
|
119
|
+
fetch('http://localhost:5050/users')
|
|
120
|
+
.then(res => res.json())
|
|
121
|
+
.then(console.log);
|
|
182
122
|
```
|
|
183
123
|
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
<details>
|
|
187
|
-
<summary><strong>Axios</strong></summary>
|
|
188
|
-
|
|
189
|
-
```javascript
|
|
190
|
-
import axios from 'axios';
|
|
124
|
+
### Axios
|
|
191
125
|
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
await axios.post(`${API}/users`, {
|
|
196
|
-
name: 'Ali',
|
|
197
|
-
email: 'ali@test.com'
|
|
126
|
+
```js
|
|
127
|
+
axios.get('http://localhost:5050/users', {
|
|
128
|
+
params: { _page: 1, _limit: 10 }
|
|
198
129
|
});
|
|
130
|
+
```
|
|
199
131
|
|
|
200
|
-
// READ
|
|
201
|
-
const { data: users } = await axios.get(`${API}/users`);
|
|
202
132
|
|
|
203
|
-
|
|
204
|
-
await axios.patch(`${API}/users/123`, {
|
|
205
|
-
name: 'Updated'
|
|
206
|
-
});
|
|
133
|
+
## π₯ Interactive CLI
|
|
207
134
|
|
|
208
|
-
|
|
209
|
-
await axios.delete(`${API}/users/123`);
|
|
210
|
-
```
|
|
135
|
+
After starting server:
|
|
211
136
|
|
|
212
|
-
|
|
137
|
+
```text
|
|
138
|
+
360-mock> POST /users {"name":"Ali"}
|
|
139
|
+
360-mock> GET /users
|
|
140
|
+
360-mock> DELETE /users/123
|
|
141
|
+
```
|
|
213
142
|
|
|
143
|
+
Commands:
|
|
214
144
|
|
|
215
|
-
|
|
145
|
+
* `list` β list resources
|
|
146
|
+
* `clear` β clear terminal
|
|
147
|
+
* `exit` β quit
|
|
216
148
|
|
|
217
|
-
| Option | Description | Default |
|
|
218
|
-
| -------- | -------------- | ---------------- |
|
|
219
|
-
| `--port` | Server port | `5050` |
|
|
220
|
-
| `--file` | Data file name | `mock-data.json` |
|
|
221
149
|
|
|
222
|
-
|
|
150
|
+
## βοΈ Options
|
|
223
151
|
|
|
224
152
|
```bash
|
|
225
153
|
npx 360-mock-server --port 4000
|
|
@@ -227,43 +155,16 @@ npx 360-mock-server --file db.json
|
|
|
227
155
|
```
|
|
228
156
|
|
|
229
157
|
|
|
230
|
-
##
|
|
231
|
-
|
|
232
|
-
| Command | Description |
|
|
233
|
-
| ---------------- | --------------------------------------- |
|
|
234
|
-
| `360-mock start` | Start server only (no interactive mode) |
|
|
235
|
-
| `360-mock init` | Create an empty data file |
|
|
236
|
-
| `360-mock list` | List all resources |
|
|
237
|
-
| `360-mock reset` | Clear all stored data |
|
|
238
|
-
|
|
158
|
+
## πΎ Storage
|
|
239
159
|
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
* β
Zero-config setup
|
|
243
|
-
* β
Supports **any REST endpoint**
|
|
244
|
-
* β
Full CRUD operations
|
|
245
|
-
* β
**Auto-generate fake data** with Faker.js
|
|
246
|
-
* β
Auto-generated unique IDs
|
|
247
|
-
* β
Automatic timestamps (`createdAt`, `updatedAt`)
|
|
248
|
-
* β
Persistent JSON storage
|
|
249
|
-
* β
CORS enabled
|
|
250
|
-
* β
Works with Postman & frontend apps
|
|
251
|
-
* β
Perfect for mock APIs & demos
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
## πΎ Data Storage
|
|
255
|
-
|
|
256
|
-
All data is stored locally in:
|
|
160
|
+
Data is stored locally in:
|
|
257
161
|
|
|
258
162
|
```
|
|
259
163
|
mock-data.json
|
|
260
164
|
```
|
|
261
165
|
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
## π License
|
|
265
|
-
|
|
266
|
-
This package is under the premises of **360XpertSolution** and built by **zahidrahimoon**.
|
|
166
|
+
## πͺͺ License
|
|
267
167
|
|
|
268
|
-
MIT Β©
|
|
168
|
+
MIT Β© **360XpertSolution**
|
|
169
|
+
Built by **zahidrahimoon**
|
|
269
170
|
|