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.
Files changed (2) hide show
  1. package/README.md +80 -179
  2. 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-configuration mock REST API designed for frontend developers.
4
- It allows you to instantly create and manage RESTful APIs **without building a backend**, making it ideal for frontend development, testing, demos, and rapid prototyping.
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
- Now with **Faker.js integration** for automatic fake data generation!
6
+ Perfect for **React / React Native / Redux / demos / testing**.
7
7
 
8
8
 
9
- ## ✨ Why 360 Mock Server?
9
+ ## ✨ Features
10
10
 
11
- * No backend setup required
12
- * Works instantly with **any endpoint**
13
- * **Auto-generate fake data** with Faker.js
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
- * Persistent JSON-based storage
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
- ## ⚑ Quick Start
30
+ ## ⚑ Start Server
35
31
 
36
32
  ```bash
37
33
  npx 360-mock-server
38
34
  ```
39
35
 
40
- That’s it! πŸŽ‰
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
- ## 🧠 Interactive CLI Mode
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
- ### Example Endpoints
47
+ ```bash
48
+ POST /users
49
+ { "name": "Ali", "email": "ali@test.com" }
90
50
 
91
- | Method | Endpoint | Body |
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
- **Required Headers**
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
- ## 🎲 Auto-Generate Fake Data with Faker.js
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
- ### Generate 50 Products with custom count
72
+ Works for **any resource**:
121
73
 
122
74
  ```bash
123
75
  POST /products
124
76
  {
125
- "fields": ["productName", "price", "category", "description", "image"],
126
- "count": 50
77
+ "fields": ["productName", "price", "category"],
78
+ "count": 20
127
79
  }
128
80
  ```
129
81
 
130
- ### Available Faker Fields
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
- > **Note:** If your POST body contains a `fields` array, it generates fake data. Otherwise, it creates a single item with your provided key-value pairs.
88
+ ### πŸ“„ Pagination (Built-in)
153
89
 
90
+ ```bash
91
+ GET /users?_page=1&_limit=5
92
+ ```
154
93
 
155
- ## πŸ”Œ Frontend Integration Examples
94
+ Response:
156
95
 
157
- <details open>
158
- <summary><strong>Fetch API</strong></summary>
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
- ```javascript
161
- const API = 'http://localhost:5050';
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
- // READ
171
- const users = await fetch(`${API}/users`).then(res => res.json());
114
+ ## πŸ’» Frontend Usage
172
115
 
173
- // UPDATE
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
- // DELETE
181
- await fetch(`${API}/users/123`, { method: 'DELETE' });
118
+ ```js
119
+ fetch('http://localhost:5050/users')
120
+ .then(res => res.json())
121
+ .then(console.log);
182
122
  ```
183
123
 
184
- </details>
185
-
186
- <details>
187
- <summary><strong>Axios</strong></summary>
188
-
189
- ```javascript
190
- import axios from 'axios';
124
+ ### Axios
191
125
 
192
- const API = 'http://localhost:5050';
193
-
194
- // CREATE
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
- // UPDATE
204
- await axios.patch(`${API}/users/123`, {
205
- name: 'Updated'
206
- });
133
+ ## πŸ–₯ Interactive CLI
207
134
 
208
- // DELETE
209
- await axios.delete(`${API}/users/123`);
210
- ```
135
+ After starting server:
211
136
 
212
- </details>
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
- ## βš™οΈ CLI Options
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
- ### Examples
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
- ## πŸ›  Additional Commands
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
- ## 🌟 Features
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
- This file is automatically created and updated in your project directory.
263
-
264
- ## πŸ“„ License
265
-
266
- This package is under the premises of **360XpertSolution** and built by **zahidrahimoon**.
166
+ ## πŸͺͺ License
267
167
 
268
- MIT Β© [zahidrahimoon](https://github.com/zahidrahimoon/)
168
+ MIT Β© **360XpertSolution**
169
+ Built by **zahidrahimoon**
269
170
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "360-mock-server",
3
- "version": "1.2.5",
3
+ "version": "1.2.6",
4
4
  "description": "πŸš€ Zero-config dynamic mock REST API server with Faker.js auto-generation for frontend developers",
5
5
  "main": "lib/server.js",
6
6
  "bin": {