360-mock-server 1.1.0 β†’ 1.1.1

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 +145 -120
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -1,190 +1,215 @@
1
1
  # πŸš€ 360 Mock Server
2
2
 
3
- Zero-config dynamic mock REST API server. Perfect for frontend development when backend isn't ready.
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.
4
5
 
5
- ## Installation
6
+
7
+ ## ✨ Why 360 Mock Server?
8
+
9
+ * No backend setup required
10
+ * Works instantly with **any endpoint**
11
+ * Interactive CLI + REST API
12
+ * Persistent JSON-based storage
13
+ * Ideal for React, React Native, Vue, Angular, Redux apps
14
+
15
+
16
+ ## πŸ“¦ Installation
17
+
18
+ Install globally using npm:
6
19
 
7
20
  ```bash
8
- # Global installation (recommended)
9
21
  npm install -g 360-mock-server
22
+ ```
23
+
24
+ Or run directly using `npx` (recommended):
10
25
 
11
- # Or use npx (no install needed)
26
+ ```bash
12
27
  npx 360-mock-server
13
28
  ```
14
29
 
15
- ## Quick Start
30
+
31
+ ## ⚑ Quick Start
16
32
 
17
33
  ```bash
18
- # Just run one command - that's it!
19
34
  npx 360-mock-server
20
35
  ```
21
36
 
22
- This will:
23
- 1. βœ… Create `mock-data.json` automatically
24
- 2. βœ… Start the server on port 3000
25
- 3. βœ… Open interactive mode for easy API requests
37
+ That’s it! πŸŽ‰
38
+ The mock server will start at:
39
+
40
+ ```
41
+ http://localhost:3000
42
+ ```
26
43
 
27
- ---
28
44
 
29
- ## Interactive Mode (Recommended!)
45
+ ## 🧠 Interactive CLI Mode
30
46
 
31
- After running `npx 360-mock-server`, you get an interactive prompt:
47
+ Once the server starts, you can interact with it directly from the terminal:
32
48
 
33
- ```
49
+ ```text
34
50
  360-mock> POST /users {"name": "Ali", "email": "ali@test.com"}
35
- πŸ“€ POST /users
36
51
  βœ… Status: 201
37
- { "id": 1234567890, "name": "Ali", "email": "ali@test.com" }
52
+ {"id": 1737745200000, "name": "Ali", "email": "ali@test.com"}
38
53
 
39
54
  360-mock> GET /users
40
- πŸ“€ GET /users
41
55
  βœ… Status: 200
42
- [{ "id": 1234567890, "name": "Ali", "email": "ali@test.com" }]
56
+ [{"id": 1737745200000, "name": "Ali", "email": "ali@test.com"}]
43
57
 
44
- 360-mock> POST /products {"name": "Laptop", "price": 999}
45
- 360-mock> GET /products
46
- 360-mock> DELETE /users/1234567890
47
- 360-mock> exit
58
+ 360-mock> DELETE /users/1737745200000
59
+ βœ… Status: 200
48
60
  ```
49
61
 
50
- ### Interactive Commands
51
-
52
- | Command | Example |
53
- |---------|---------|
54
- | GET | `GET /users` |
55
- | POST | `POST /users {"name": "Ali"}` |
56
- | PUT | `PUT /users/123 {"name": "Updated"}` |
57
- | PATCH | `PATCH /users/123 {"email": "new@test.com"}` |
58
- | DELETE | `DELETE /users/123` |
59
- | list | Show all resources |
60
- | clear | Clear screen |
61
- | help | Show help |
62
- | exit | Exit |
63
62
 
64
- ---
63
+ ## πŸ“Ÿ CLI Commands (Interactive Mode)
65
64
 
66
- ## CLI Commands
65
+ | Command | Description |
66
+ | -------------------------------------- | ---------------------------- |
67
+ | `GET /users` | Fetch all users |
68
+ | `GET /users/123` | Fetch user by ID |
69
+ | `POST /users {"name":"Ali"}` | Create a new user |
70
+ | `PUT /users/123 {"name":"New"}` | Replace entire resource |
71
+ | `PATCH /users/123 {"email":"x@y.com"}` | Update specific fields |
72
+ | `DELETE /users/123` | Delete resource |
73
+ | `list` | Show all available resources |
74
+ | `clear` | Clear terminal screen |
75
+ | `help` | Show help |
76
+ | `exit` | Exit interactive mode |
67
77
 
68
- | Command | Description |
69
- |---------|-------------|
70
- | `360-mock` | Start server + interactive mode |
71
- | `360-mock start` | Start server only |
72
- | `360-mock init` | Create mock-data.json |
73
- | `360-mock list` | Show available resources |
74
- | `360-mock reset` | Clear all data |
78
+ ## πŸ§ͺ Using with Postman / REST Clients
75
79
 
76
- ### Options
80
+ **Base URL**
77
81
 
78
- ```bash
79
- 360-mock --port 4000 # Custom port
80
- 360-mock --file db.json # Custom data file
81
- 360-mock --help # Show help
82
- 360-mock --version # Show version
83
82
  ```
84
-
85
- ---
86
-
87
- ## API Endpoints
88
-
89
- ### Any endpoint works automatically!
90
-
91
- Just POST to any endpoint - it creates the resource:
92
-
93
- ```bash
94
- # These all work without configuration:
95
- POST /users
96
- POST /products
97
- POST /orders
98
- POST /anything-you-want
83
+ http://localhost:3000
99
84
  ```
100
85
 
101
- ### Full CRUD Operations
86
+ ### Example Endpoints
102
87
 
103
- | Method | Endpoint | Description |
104
- |--------|----------|-------------|
105
- | GET | `/users` | Get all users |
106
- | GET | `/users/1` | Get user by ID |
107
- | POST | `/users` | Create user |
108
- | PUT | `/users/1` | Replace user |
109
- | PATCH | `/users/1` | Update user |
110
- | DELETE | `/users/1` | Delete user |
111
- | DELETE | `/users` | Delete all users |
88
+ | Method | Endpoint | Body |
89
+ | ------ | ------------ | ----------------------------- |
90
+ | GET | `/users` | β€” |
91
+ | GET | `/users/123` | β€” |
92
+ | POST | `/users` | `{ "name": "Ali" }` |
93
+ | PUT | `/users/123` | `{ "name": "Updated" }` |
94
+ | PATCH | `/users/123` | `{ "email": "new@test.com" }` |
95
+ | DELETE | `/users/123` | β€” |
112
96
 
113
- ### Query Parameters
97
+ **Required Headers**
114
98
 
115
- ```bash
116
- GET /users?name=john # Filter by name
117
- GET /users?_sort=name # Sort by field
118
- GET /users?_order=desc # Sort order
119
- GET /users?_limit=10&_page=2 # Pagination
99
+ ```
100
+ Content-Type: application/json
120
101
  ```
121
102
 
122
- ---
123
103
 
124
- ## Frontend Examples
104
+ ## πŸ”Œ Frontend Integration Examples
125
105
 
126
- ### Fetch API
106
+ <details open>
107
+ <summary><strong>Fetch API</strong></summary>
127
108
 
128
109
  ```javascript
129
- // Create
130
- const user = await fetch('http://localhost:3000/users', {
110
+ const API = 'http://localhost:3000';
111
+
112
+ // CREATE
113
+ await fetch(`${API}/users`, {
131
114
  method: 'POST',
132
115
  headers: { 'Content-Type': 'application/json' },
133
116
  body: JSON.stringify({ name: 'Ali', email: 'ali@test.com' })
134
- }).then(r => r.json());
135
-
136
- // Read all
137
- const users = await fetch('http://localhost:3000/users').then(r => r.json());
117
+ });
138
118
 
139
- // Read one
140
- const user = await fetch('http://localhost:3000/users/1').then(r => r.json());
119
+ // READ
120
+ const users = await fetch(`${API}/users`).then(res => res.json());
141
121
 
142
- // Update
143
- await fetch('http://localhost:3000/users/1', {
122
+ // UPDATE
123
+ await fetch(`${API}/users/123`, {
144
124
  method: 'PATCH',
145
125
  headers: { 'Content-Type': 'application/json' },
146
- body: JSON.stringify({ name: 'Ali Updated' })
126
+ body: JSON.stringify({ name: 'Updated' })
147
127
  });
148
128
 
149
- // Delete
150
- await fetch('http://localhost:3000/users/1', { method: 'DELETE' });
129
+ // DELETE
130
+ await fetch(`${API}/users/123`, { method: 'DELETE' });
151
131
  ```
152
132
 
153
- ### Axios
133
+ </details>
134
+
135
+ <details>
136
+ <summary><strong>Axios</strong></summary>
154
137
 
155
138
  ```javascript
156
139
  import axios from 'axios';
157
- const api = axios.create({ baseURL: 'http://localhost:3000' });
158
140
 
159
- // Create
160
- const { data: user } = await api.post('/users', { name: 'Ali' });
141
+ const API = 'http://localhost:3000';
142
+
143
+ // CREATE
144
+ await axios.post(`${API}/users`, {
145
+ name: 'Ali',
146
+ email: 'ali@test.com'
147
+ });
148
+
149
+ // READ
150
+ const { data: users } = await axios.get(`${API}/users`);
151
+
152
+ // UPDATE
153
+ await axios.patch(`${API}/users/123`, {
154
+ name: 'Updated'
155
+ });
156
+
157
+ // DELETE
158
+ await axios.delete(`${API}/users/123`);
159
+ ```
160
+
161
+ </details>
162
+
161
163
 
162
- // Read
163
- const { data: users } = await api.get('/users');
164
+ ## βš™οΈ CLI Options
164
165
 
165
- // Update
166
- await api.patch(`/users/${id}`, { name: 'Updated' });
166
+ | Option | Description | Default |
167
+ | -------- | -------------- | ---------------- |
168
+ | `--port` | Server port | `3000` |
169
+ | `--file` | Data file name | `mock-data.json` |
167
170
 
168
- // Delete
169
- await api.delete(`/users/${id}`);
171
+ ### Examples
172
+
173
+ ```bash
174
+ npx 360-mock-server --port 4000
175
+ npx 360-mock-server --file db.json
170
176
  ```
171
177
 
172
- ---
173
178
 
174
- ## Features
179
+ ## πŸ›  Additional Commands
180
+
181
+ | Command | Description |
182
+ | ---------------- | --------------------------------------- |
183
+ | `360-mock start` | Start server only (no interactive mode) |
184
+ | `360-mock init` | Create an empty data file |
185
+ | `360-mock list` | List all resources |
186
+ | `360-mock reset` | Clear all stored data |
187
+
188
+
189
+ ## 🌟 Features
190
+
191
+ * βœ… Zero-config setup
192
+ * βœ… Supports **any REST endpoint**
193
+ * βœ… Full CRUD operations
194
+ * βœ… Auto-generated unique IDs
195
+ * βœ… Automatic timestamps (`createdAt`, `updatedAt`)
196
+ * βœ… Persistent JSON storage
197
+ * βœ… CORS enabled
198
+ * βœ… Works with Postman & frontend apps
199
+ * βœ… Perfect for mock APIs & demos
175
200
 
176
- - βœ… **Zero config** - Works out of the box
177
- - βœ… **Any endpoint** - Auto-creates resources
178
- - βœ… **Full CRUD** - GET, POST, PUT, PATCH, DELETE
179
- - βœ… **Filtering** - Query parameter support
180
- - βœ… **Sorting** - `?_sort=field&_order=desc`
181
- - βœ… **Pagination** - `?_limit=10&_page=1`
182
- - βœ… **Auto IDs** - Generated automatically
183
- - βœ… **Timestamps** - createdAt, updatedAt
184
- - βœ… **CORS enabled** - Works with any frontend
185
201
 
186
- ---
202
+ ## πŸ’Ύ Data Storage
187
203
 
188
- ## License
204
+ All data is stored locally in:
205
+
206
+ ```
207
+ mock-data.json
208
+ ```
209
+
210
+ This file is automatically created and updated in your project directory.
211
+
212
+ ## πŸ“„ License
189
213
 
190
214
  MIT Β© [zahidrahimoon](https://github.com/zahidrahimoon)
215
+
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "360-mock-server",
3
- "version": "1.1.0",
3
+ "version": "1.1.1",
4
4
  "description": "πŸš€ Zero-config dynamic mock REST API server for frontend developers",
5
5
  "main": "lib/server.js",
6
6
  "bin": {