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.
- package/README.md +145 -120
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,190 +1,215 @@
|
|
|
1
1
|
# π 360 Mock Server
|
|
2
2
|
|
|
3
|
-
|
|
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
|
-
|
|
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
|
-
|
|
26
|
+
```bash
|
|
12
27
|
npx 360-mock-server
|
|
13
28
|
```
|
|
14
29
|
|
|
15
|
-
|
|
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
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
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
|
|
45
|
+
## π§ Interactive CLI Mode
|
|
30
46
|
|
|
31
|
-
|
|
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
|
-
{
|
|
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
|
-
[{
|
|
56
|
+
[{"id": 1737745200000, "name": "Ali", "email": "ali@test.com"}]
|
|
43
57
|
|
|
44
|
-
360-mock>
|
|
45
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
###
|
|
86
|
+
### Example Endpoints
|
|
102
87
|
|
|
103
|
-
| Method | Endpoint
|
|
104
|
-
|
|
105
|
-
| GET
|
|
106
|
-
| GET
|
|
107
|
-
| POST
|
|
108
|
-
| PUT
|
|
109
|
-
| PATCH
|
|
110
|
-
| DELETE | `/users/
|
|
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
|
-
|
|
97
|
+
**Required Headers**
|
|
114
98
|
|
|
115
|
-
```
|
|
116
|
-
|
|
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
|
-
|
|
106
|
+
<details open>
|
|
107
|
+
<summary><strong>Fetch API</strong></summary>
|
|
127
108
|
|
|
128
109
|
```javascript
|
|
129
|
-
|
|
130
|
-
|
|
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
|
-
})
|
|
135
|
-
|
|
136
|
-
// Read all
|
|
137
|
-
const users = await fetch('http://localhost:3000/users').then(r => r.json());
|
|
117
|
+
});
|
|
138
118
|
|
|
139
|
-
//
|
|
140
|
-
const
|
|
119
|
+
// READ
|
|
120
|
+
const users = await fetch(`${API}/users`).then(res => res.json());
|
|
141
121
|
|
|
142
|
-
//
|
|
143
|
-
await fetch(
|
|
122
|
+
// UPDATE
|
|
123
|
+
await fetch(`${API}/users/123`, {
|
|
144
124
|
method: 'PATCH',
|
|
145
125
|
headers: { 'Content-Type': 'application/json' },
|
|
146
|
-
body: JSON.stringify({ name: '
|
|
126
|
+
body: JSON.stringify({ name: 'Updated' })
|
|
147
127
|
});
|
|
148
128
|
|
|
149
|
-
//
|
|
150
|
-
await fetch(
|
|
129
|
+
// DELETE
|
|
130
|
+
await fetch(`${API}/users/123`, { method: 'DELETE' });
|
|
151
131
|
```
|
|
152
132
|
|
|
153
|
-
|
|
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
|
-
|
|
160
|
-
|
|
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
|
-
|
|
163
|
-
const { data: users } = await api.get('/users');
|
|
164
|
+
## βοΈ CLI Options
|
|
164
165
|
|
|
165
|
-
|
|
166
|
-
|
|
166
|
+
| Option | Description | Default |
|
|
167
|
+
| -------- | -------------- | ---------------- |
|
|
168
|
+
| `--port` | Server port | `3000` |
|
|
169
|
+
| `--file` | Data file name | `mock-data.json` |
|
|
167
170
|
|
|
168
|
-
|
|
169
|
-
|
|
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
|
-
##
|
|
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
|
-
|
|
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
|
+
|