api-mocker 0.1.0__py3-none-any.whl → 0.1.2__py3-none-any.whl
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.
- api_mocker/core.py +3 -3
- api_mocker-0.1.2.dist-info/METADATA +657 -0
- {api_mocker-0.1.0.dist-info → api_mocker-0.1.2.dist-info}/RECORD +7 -7
- api_mocker-0.1.0.dist-info/METADATA +0 -98
- {api_mocker-0.1.0.dist-info → api_mocker-0.1.2.dist-info}/WHEEL +0 -0
- {api_mocker-0.1.0.dist-info → api_mocker-0.1.2.dist-info}/entry_points.txt +0 -0
- {api_mocker-0.1.0.dist-info → api_mocker-0.1.2.dist-info}/licenses/LICENSE +0 -0
- {api_mocker-0.1.0.dist-info → api_mocker-0.1.2.dist-info}/top_level.txt +0 -0
api_mocker/core.py
CHANGED
|
@@ -57,9 +57,9 @@ class AdvancedRouter:
|
|
|
57
57
|
self.routes.append(route)
|
|
58
58
|
|
|
59
59
|
def find_route(self, path: str, method: str) -> Optional[RouteConfig]:
|
|
60
|
-
# Normalize path -
|
|
61
|
-
if path.startswith('/'):
|
|
62
|
-
path = path
|
|
60
|
+
# Normalize path - ensure it starts with /
|
|
61
|
+
if not path.startswith('/'):
|
|
62
|
+
path = '/' + path
|
|
63
63
|
|
|
64
64
|
print(f"Looking for route: {method} {path}")
|
|
65
65
|
print(f"Available routes: {[(r.method, r.path) for r in self.routes]}")
|
|
@@ -0,0 +1,657 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: api-mocker
|
|
3
|
+
Version: 0.1.2
|
|
4
|
+
Summary: The industry-standard, production-ready, free API mocking and development acceleration tool.
|
|
5
|
+
Author-email: sherin joseph roy <sherin.joseph2217@gmail.com>
|
|
6
|
+
License: MIT License
|
|
7
|
+
|
|
8
|
+
Copyright (c) 2024 sherin joseph roy
|
|
9
|
+
|
|
10
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
11
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
12
|
+
in the Software without restriction, including without limitation the rights
|
|
13
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
14
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
15
|
+
furnished to do so, subject to the following conditions:
|
|
16
|
+
|
|
17
|
+
The above copyright notice and this permission notice shall be included in all
|
|
18
|
+
copies or substantial portions of the Software.
|
|
19
|
+
|
|
20
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
21
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
22
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
23
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
24
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
25
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
26
|
+
SOFTWARE.
|
|
27
|
+
Project-URL: Homepage, https://github.com/Sherin-SEF-AI/api-mocker
|
|
28
|
+
Project-URL: Repository, https://github.com/Sherin-SEF-AI/api-mocker.git
|
|
29
|
+
Keywords: api,mock,mocking,development,testing,openapi,swagger,cli,devops
|
|
30
|
+
Classifier: Programming Language :: Python :: 3
|
|
31
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
32
|
+
Classifier: Operating System :: OS Independent
|
|
33
|
+
Classifier: Development Status :: 3 - Alpha
|
|
34
|
+
Classifier: Intended Audience :: Developers
|
|
35
|
+
Classifier: Topic :: Software Development :: Testing
|
|
36
|
+
Classifier: Topic :: Software Development :: Libraries :: Application Frameworks
|
|
37
|
+
Requires-Python: >=3.8
|
|
38
|
+
Description-Content-Type: text/markdown
|
|
39
|
+
License-File: LICENSE
|
|
40
|
+
Requires-Dist: typer>=0.9.0
|
|
41
|
+
Requires-Dist: fastapi>=0.100.0
|
|
42
|
+
Requires-Dist: uvicorn>=0.23.0
|
|
43
|
+
Requires-Dist: PyYAML>=6.0
|
|
44
|
+
Requires-Dist: toml>=0.10.2
|
|
45
|
+
Requires-Dist: pytest>=7.0.0
|
|
46
|
+
Requires-Dist: httpx>=0.24.0
|
|
47
|
+
Requires-Dist: rich>=13.0.0
|
|
48
|
+
Dynamic: license-file
|
|
49
|
+
|
|
50
|
+
# api-mocker
|
|
51
|
+
|
|
52
|
+
The industry-standard, production-ready, free API mocking and development acceleration tool.
|
|
53
|
+
|
|
54
|
+
## 🚀 Project Mission
|
|
55
|
+
Create the most comprehensive, user-friendly, and feature-rich API mocking solution to eliminate API dependency bottlenecks and accelerate development workflows for all developers.
|
|
56
|
+
|
|
57
|
+
## ✨ Features
|
|
58
|
+
- **Robust HTTP mock server** supporting all HTTP methods (GET, POST, PUT, DELETE, PATCH, etc.)
|
|
59
|
+
- **Dynamic and static response generation** with template support
|
|
60
|
+
- **OpenAPI/Swagger/Postman import/export** for seamless integration
|
|
61
|
+
- **CLI and Python API interfaces** for maximum flexibility
|
|
62
|
+
- **Hot-reloading** with config file support (JSON/YAML/TOML)
|
|
63
|
+
- **Request recording, replay, and proxy mode** for real API simulation
|
|
64
|
+
- **Schema-based data generation** and validation
|
|
65
|
+
- **Advanced routing, middleware, and authentication simulation**
|
|
66
|
+
- **Data persistence, state management, and in-memory DB**
|
|
67
|
+
- **Performance, monitoring, and analytics tools**
|
|
68
|
+
- **Framework integrations** (Django, Flask, FastAPI, Node.js, etc.)
|
|
69
|
+
- **Docker, CI/CD, and cloud deployment support**
|
|
70
|
+
- **Team collaboration and plugin architecture**
|
|
71
|
+
|
|
72
|
+
## 📦 Installation
|
|
73
|
+
|
|
74
|
+
### From PyPI (Recommended)
|
|
75
|
+
```bash
|
|
76
|
+
pip install api-mocker
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
### From Source
|
|
80
|
+
```bash
|
|
81
|
+
git clone https://github.com/your-username/api-mocker.git
|
|
82
|
+
cd api-mocker
|
|
83
|
+
pip install -e .
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
## 🚀 Quick Start
|
|
87
|
+
|
|
88
|
+
### 1. Basic Usage
|
|
89
|
+
Create a simple mock configuration:
|
|
90
|
+
|
|
91
|
+
```yaml
|
|
92
|
+
# simple-mock.yaml
|
|
93
|
+
server:
|
|
94
|
+
host: "127.0.0.1"
|
|
95
|
+
port: 8000
|
|
96
|
+
debug: true
|
|
97
|
+
|
|
98
|
+
routes:
|
|
99
|
+
- method: "GET"
|
|
100
|
+
path: "/api/health"
|
|
101
|
+
response:
|
|
102
|
+
status_code: 200
|
|
103
|
+
body:
|
|
104
|
+
status: "healthy"
|
|
105
|
+
timestamp: "{{ datetime.now().isoformat() }}"
|
|
106
|
+
version: "1.0.0"
|
|
107
|
+
|
|
108
|
+
- method: "GET"
|
|
109
|
+
path: "/api/users"
|
|
110
|
+
response:
|
|
111
|
+
status_code: 200
|
|
112
|
+
body:
|
|
113
|
+
users:
|
|
114
|
+
- id: 1
|
|
115
|
+
name: "John Doe"
|
|
116
|
+
email: "john@example.com"
|
|
117
|
+
- id: 2
|
|
118
|
+
name: "Jane Smith"
|
|
119
|
+
email: "jane@example.com"
|
|
120
|
+
|
|
121
|
+
- method: "POST"
|
|
122
|
+
path: "/api/users"
|
|
123
|
+
response:
|
|
124
|
+
status_code: 201
|
|
125
|
+
body:
|
|
126
|
+
id: "{{ random.randint(1000, 9999) }}"
|
|
127
|
+
message: "User created successfully"
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
Start the mock server:
|
|
131
|
+
```bash
|
|
132
|
+
api-mocker start --config simple-mock.yaml
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
### 2. Test Your Mock API
|
|
136
|
+
```bash
|
|
137
|
+
# Test health endpoint
|
|
138
|
+
curl http://127.0.0.1:8000/api/health
|
|
139
|
+
|
|
140
|
+
# Test users endpoint
|
|
141
|
+
curl http://127.0.0.1:8000/api/users
|
|
142
|
+
|
|
143
|
+
# Create a new user
|
|
144
|
+
curl -X POST http://127.0.0.1:8000/api/users \
|
|
145
|
+
-H "Content-Type: application/json" \
|
|
146
|
+
-d '{"name": "New User", "email": "new@example.com"}'
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
## 📚 Complete Documentation
|
|
150
|
+
|
|
151
|
+
### CLI Commands
|
|
152
|
+
|
|
153
|
+
#### Start Server
|
|
154
|
+
```bash
|
|
155
|
+
# Basic start
|
|
156
|
+
api-mocker start --config config.yaml
|
|
157
|
+
|
|
158
|
+
# With custom host and port
|
|
159
|
+
api-mocker start --config config.yaml --host 0.0.0.0 --port 9000
|
|
160
|
+
|
|
161
|
+
# With verbose logging
|
|
162
|
+
api-mocker start --config config.yaml --verbose
|
|
163
|
+
|
|
164
|
+
# With hot reload
|
|
165
|
+
api-mocker start --config config.yaml --reload
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
#### Import Specifications
|
|
169
|
+
```bash
|
|
170
|
+
# Import OpenAPI/Swagger spec
|
|
171
|
+
api-mocker import openapi --file swagger.json --output mock-config.yaml
|
|
172
|
+
|
|
173
|
+
# Import Postman collection
|
|
174
|
+
api-mocker import postman --file collection.json --output mock-config.yaml
|
|
175
|
+
|
|
176
|
+
# Import with custom base URL
|
|
177
|
+
api-mocker import openapi --file api-spec.yaml --base-url https://api.example.com
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
#### Record and Replay
|
|
181
|
+
```bash
|
|
182
|
+
# Record real API calls
|
|
183
|
+
api-mocker record --target https://api.example.com --output recorded.yaml
|
|
184
|
+
|
|
185
|
+
# Replay recorded requests
|
|
186
|
+
api-mocker replay --file recorded.yaml --config mock-config.yaml
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
#### Plugin Management
|
|
190
|
+
```bash
|
|
191
|
+
# List available plugins
|
|
192
|
+
api-mocker plugins list
|
|
193
|
+
|
|
194
|
+
# Install plugin
|
|
195
|
+
api-mocker plugins install auth-plugin
|
|
196
|
+
|
|
197
|
+
# Enable plugin
|
|
198
|
+
api-mocker plugins enable auth-plugin
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
#### Testing
|
|
202
|
+
```bash
|
|
203
|
+
# Run test suite
|
|
204
|
+
api-mocker test --config mock-config.yaml --test-file tests.yaml
|
|
205
|
+
|
|
206
|
+
# Test specific endpoint
|
|
207
|
+
api-mocker test --config mock-config.yaml --endpoint "/api/users"
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
#### Monitoring
|
|
211
|
+
```bash
|
|
212
|
+
# Start monitoring dashboard
|
|
213
|
+
api-mocker monitor --config mock-config.yaml --port 8080
|
|
214
|
+
|
|
215
|
+
# Export metrics
|
|
216
|
+
api-mocker monitor --config mock-config.yaml --export metrics.json
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
#### Export
|
|
220
|
+
```bash
|
|
221
|
+
# Export to OpenAPI
|
|
222
|
+
api-mocker export openapi --config mock-config.yaml --output api-spec.yaml
|
|
223
|
+
|
|
224
|
+
# Export to Postman
|
|
225
|
+
api-mocker export postman --config mock-config.yaml --output collection.json
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
#### Project Management
|
|
229
|
+
```bash
|
|
230
|
+
# Initialize new project
|
|
231
|
+
api-mocker init --name my-api-project
|
|
232
|
+
|
|
233
|
+
# Create from template
|
|
234
|
+
api-mocker init --template rest-api --name my-rest-api
|
|
235
|
+
```
|
|
236
|
+
|
|
237
|
+
### Configuration Examples
|
|
238
|
+
|
|
239
|
+
#### Advanced Mock Configuration
|
|
240
|
+
```yaml
|
|
241
|
+
# advanced-mock.yaml
|
|
242
|
+
server:
|
|
243
|
+
host: "127.0.0.1"
|
|
244
|
+
port: 8000
|
|
245
|
+
debug: true
|
|
246
|
+
cors:
|
|
247
|
+
enabled: true
|
|
248
|
+
origins: ["http://localhost:3000", "https://myapp.com"]
|
|
249
|
+
rate_limit:
|
|
250
|
+
enabled: true
|
|
251
|
+
requests_per_minute: 100
|
|
252
|
+
|
|
253
|
+
middleware:
|
|
254
|
+
- name: "auth"
|
|
255
|
+
config:
|
|
256
|
+
type: "bearer"
|
|
257
|
+
tokens: ["secret-token-123"]
|
|
258
|
+
- name: "logging"
|
|
259
|
+
config:
|
|
260
|
+
level: "INFO"
|
|
261
|
+
format: "json"
|
|
262
|
+
|
|
263
|
+
routes:
|
|
264
|
+
- method: "GET"
|
|
265
|
+
path: "/api/users/{user_id}"
|
|
266
|
+
auth_required: true
|
|
267
|
+
response:
|
|
268
|
+
status_code: 200
|
|
269
|
+
headers:
|
|
270
|
+
Content-Type: "application/json"
|
|
271
|
+
body:
|
|
272
|
+
id: "{{ params.user_id }}"
|
|
273
|
+
name: "{{ fake.name() }}"
|
|
274
|
+
email: "{{ fake.email() }}"
|
|
275
|
+
created_at: "{{ datetime.now().isoformat() }}"
|
|
276
|
+
|
|
277
|
+
- method: "POST"
|
|
278
|
+
path: "/api/users"
|
|
279
|
+
auth_required: true
|
|
280
|
+
validation:
|
|
281
|
+
schema:
|
|
282
|
+
type: "object"
|
|
283
|
+
required: ["name", "email"]
|
|
284
|
+
properties:
|
|
285
|
+
name:
|
|
286
|
+
type: "string"
|
|
287
|
+
minLength: 2
|
|
288
|
+
email:
|
|
289
|
+
type: "string"
|
|
290
|
+
format: "email"
|
|
291
|
+
response:
|
|
292
|
+
status_code: 201
|
|
293
|
+
body:
|
|
294
|
+
id: "{{ random.randint(1000, 9999) }}"
|
|
295
|
+
name: "{{ request.body.name }}"
|
|
296
|
+
email: "{{ request.body.email }}"
|
|
297
|
+
created_at: "{{ datetime.now().isoformat() }}"
|
|
298
|
+
|
|
299
|
+
- method: "GET"
|
|
300
|
+
path: "/api/search"
|
|
301
|
+
response:
|
|
302
|
+
status_code: 200
|
|
303
|
+
body:
|
|
304
|
+
results:
|
|
305
|
+
- "{{ fake.sentence() }}"
|
|
306
|
+
- "{{ fake.sentence() }}"
|
|
307
|
+
- "{{ fake.sentence() }}"
|
|
308
|
+
total: "{{ random.randint(10, 100) }}"
|
|
309
|
+
page: "{{ request.query.page or 1 }}"
|
|
310
|
+
|
|
311
|
+
database:
|
|
312
|
+
type: "sqlite"
|
|
313
|
+
path: "mock_data.db"
|
|
314
|
+
tables:
|
|
315
|
+
users:
|
|
316
|
+
- id: 1
|
|
317
|
+
name: "John Doe"
|
|
318
|
+
email: "john@example.com"
|
|
319
|
+
- id: 2
|
|
320
|
+
name: "Jane Smith"
|
|
321
|
+
email: "jane@example.com"
|
|
322
|
+
|
|
323
|
+
plugins:
|
|
324
|
+
- name: "faker"
|
|
325
|
+
config:
|
|
326
|
+
locale: "en_US"
|
|
327
|
+
- name: "jwt"
|
|
328
|
+
config:
|
|
329
|
+
secret: "your-secret-key"
|
|
330
|
+
```
|
|
331
|
+
|
|
332
|
+
#### Testing Configuration
|
|
333
|
+
```yaml
|
|
334
|
+
# tests.yaml
|
|
335
|
+
tests:
|
|
336
|
+
- name: "Health Check"
|
|
337
|
+
request:
|
|
338
|
+
method: "GET"
|
|
339
|
+
url: "/api/health"
|
|
340
|
+
expected:
|
|
341
|
+
status_code: 200
|
|
342
|
+
body:
|
|
343
|
+
status: "healthy"
|
|
344
|
+
|
|
345
|
+
- name: "Create User"
|
|
346
|
+
request:
|
|
347
|
+
method: "POST"
|
|
348
|
+
url: "/api/users"
|
|
349
|
+
headers:
|
|
350
|
+
Authorization: "Bearer secret-token-123"
|
|
351
|
+
Content-Type: "application/json"
|
|
352
|
+
body:
|
|
353
|
+
name: "Test User"
|
|
354
|
+
email: "test@example.com"
|
|
355
|
+
expected:
|
|
356
|
+
status_code: 201
|
|
357
|
+
body:
|
|
358
|
+
name: "Test User"
|
|
359
|
+
email: "test@example.com"
|
|
360
|
+
|
|
361
|
+
- name: "Get User"
|
|
362
|
+
request:
|
|
363
|
+
method: "GET"
|
|
364
|
+
url: "/api/users/1"
|
|
365
|
+
headers:
|
|
366
|
+
Authorization: "Bearer secret-token-123"
|
|
367
|
+
expected:
|
|
368
|
+
status_code: 200
|
|
369
|
+
body:
|
|
370
|
+
id: "1"
|
|
371
|
+
```
|
|
372
|
+
|
|
373
|
+
### Python API Usage
|
|
374
|
+
|
|
375
|
+
#### Basic Server
|
|
376
|
+
```python
|
|
377
|
+
from api_mocker import MockServer
|
|
378
|
+
|
|
379
|
+
# Create server from config file
|
|
380
|
+
server = MockServer(config_path="config.yaml")
|
|
381
|
+
server.start()
|
|
382
|
+
|
|
383
|
+
# Or create server programmatically
|
|
384
|
+
from api_mocker import MockServer, Route, Response
|
|
385
|
+
|
|
386
|
+
routes = [
|
|
387
|
+
Route(
|
|
388
|
+
method="GET",
|
|
389
|
+
path="/api/health",
|
|
390
|
+
response=Response(
|
|
391
|
+
status_code=200,
|
|
392
|
+
body={"status": "healthy"}
|
|
393
|
+
)
|
|
394
|
+
)
|
|
395
|
+
]
|
|
396
|
+
|
|
397
|
+
server = MockServer(routes=routes)
|
|
398
|
+
server.start()
|
|
399
|
+
```
|
|
400
|
+
|
|
401
|
+
#### Advanced Usage
|
|
402
|
+
```python
|
|
403
|
+
from api_mocker import MockServer, Route, Response, Middleware
|
|
404
|
+
from api_mocker.plugins import FakerPlugin
|
|
405
|
+
|
|
406
|
+
# Create custom middleware
|
|
407
|
+
class CustomMiddleware(Middleware):
|
|
408
|
+
def process_request(self, request):
|
|
409
|
+
print(f"Processing request: {request.method} {request.path}")
|
|
410
|
+
return request
|
|
411
|
+
|
|
412
|
+
def process_response(self, response):
|
|
413
|
+
response.headers["X-Custom-Header"] = "processed"
|
|
414
|
+
return response
|
|
415
|
+
|
|
416
|
+
# Create server with plugins and middleware
|
|
417
|
+
server = MockServer(
|
|
418
|
+
config_path="config.yaml",
|
|
419
|
+
middleware=[CustomMiddleware()],
|
|
420
|
+
plugins=[FakerPlugin()]
|
|
421
|
+
)
|
|
422
|
+
|
|
423
|
+
# Add routes dynamically
|
|
424
|
+
server.add_route(
|
|
425
|
+
Route(
|
|
426
|
+
method="GET",
|
|
427
|
+
path="/api/dynamic",
|
|
428
|
+
response=Response(
|
|
429
|
+
status_code=200,
|
|
430
|
+
body={"message": "Dynamic route added!"}
|
|
431
|
+
)
|
|
432
|
+
)
|
|
433
|
+
)
|
|
434
|
+
|
|
435
|
+
server.start()
|
|
436
|
+
```
|
|
437
|
+
|
|
438
|
+
#### Testing with Python
|
|
439
|
+
```python
|
|
440
|
+
from api_mocker import MockServer
|
|
441
|
+
import requests
|
|
442
|
+
|
|
443
|
+
# Start server
|
|
444
|
+
server = MockServer(config_path="test-config.yaml")
|
|
445
|
+
server.start()
|
|
446
|
+
|
|
447
|
+
# Test endpoints
|
|
448
|
+
response = requests.get("http://127.0.0.1:8000/api/health")
|
|
449
|
+
assert response.status_code == 200
|
|
450
|
+
assert response.json()["status"] == "healthy"
|
|
451
|
+
|
|
452
|
+
# Stop server
|
|
453
|
+
server.stop()
|
|
454
|
+
```
|
|
455
|
+
|
|
456
|
+
### Template Variables
|
|
457
|
+
|
|
458
|
+
api-mocker supports dynamic template variables in responses:
|
|
459
|
+
|
|
460
|
+
```yaml
|
|
461
|
+
routes:
|
|
462
|
+
- method: "GET"
|
|
463
|
+
path: "/api/dynamic"
|
|
464
|
+
response:
|
|
465
|
+
status_code: 200
|
|
466
|
+
body:
|
|
467
|
+
# Request information
|
|
468
|
+
method: "{{ request.method }}"
|
|
469
|
+
path: "{{ request.path }}"
|
|
470
|
+
headers: "{{ request.headers }}"
|
|
471
|
+
query: "{{ request.query }}"
|
|
472
|
+
|
|
473
|
+
# URL parameters
|
|
474
|
+
user_id: "{{ params.user_id }}"
|
|
475
|
+
|
|
476
|
+
# Random data
|
|
477
|
+
random_id: "{{ random.randint(1, 1000) }}"
|
|
478
|
+
random_name: "{{ fake.name() }}"
|
|
479
|
+
random_email: "{{ fake.email() }}"
|
|
480
|
+
|
|
481
|
+
# Date/time
|
|
482
|
+
timestamp: "{{ datetime.now().isoformat() }}"
|
|
483
|
+
date: "{{ datetime.now().strftime('%Y-%m-%d') }}"
|
|
484
|
+
|
|
485
|
+
# Request body (for POST/PUT)
|
|
486
|
+
received_data: "{{ request.body }}"
|
|
487
|
+
```
|
|
488
|
+
|
|
489
|
+
### Authentication Examples
|
|
490
|
+
|
|
491
|
+
#### Bearer Token
|
|
492
|
+
```yaml
|
|
493
|
+
middleware:
|
|
494
|
+
- name: "auth"
|
|
495
|
+
config:
|
|
496
|
+
type: "bearer"
|
|
497
|
+
tokens: ["secret-token-123", "another-token"]
|
|
498
|
+
|
|
499
|
+
routes:
|
|
500
|
+
- method: "GET"
|
|
501
|
+
path: "/api/protected"
|
|
502
|
+
auth_required: true
|
|
503
|
+
response:
|
|
504
|
+
status_code: 200
|
|
505
|
+
body:
|
|
506
|
+
message: "Access granted"
|
|
507
|
+
```
|
|
508
|
+
|
|
509
|
+
#### API Key
|
|
510
|
+
```yaml
|
|
511
|
+
middleware:
|
|
512
|
+
- name: "auth"
|
|
513
|
+
config:
|
|
514
|
+
type: "api_key"
|
|
515
|
+
header: "X-API-Key"
|
|
516
|
+
keys: ["api-key-123", "api-key-456"]
|
|
517
|
+
```
|
|
518
|
+
|
|
519
|
+
#### Basic Auth
|
|
520
|
+
```yaml
|
|
521
|
+
middleware:
|
|
522
|
+
- name: "auth"
|
|
523
|
+
config:
|
|
524
|
+
type: "basic"
|
|
525
|
+
users:
|
|
526
|
+
admin: "password123"
|
|
527
|
+
user: "password456"
|
|
528
|
+
```
|
|
529
|
+
|
|
530
|
+
### Database Integration
|
|
531
|
+
|
|
532
|
+
```yaml
|
|
533
|
+
database:
|
|
534
|
+
type: "sqlite"
|
|
535
|
+
path: "mock_data.db"
|
|
536
|
+
tables:
|
|
537
|
+
users:
|
|
538
|
+
- id: 1
|
|
539
|
+
name: "John Doe"
|
|
540
|
+
email: "john@example.com"
|
|
541
|
+
role: "admin"
|
|
542
|
+
- id: 2
|
|
543
|
+
name: "Jane Smith"
|
|
544
|
+
email: "jane@example.com"
|
|
545
|
+
role: "user"
|
|
546
|
+
|
|
547
|
+
routes:
|
|
548
|
+
- method: "GET"
|
|
549
|
+
path: "/api/users"
|
|
550
|
+
response:
|
|
551
|
+
status_code: 200
|
|
552
|
+
body:
|
|
553
|
+
users: "{{ db.query('SELECT * FROM users') }}"
|
|
554
|
+
|
|
555
|
+
- method: "GET"
|
|
556
|
+
path: "/api/users/{user_id}"
|
|
557
|
+
response:
|
|
558
|
+
status_code: 200
|
|
559
|
+
body:
|
|
560
|
+
user: "{{ db.query_one('SELECT * FROM users WHERE id = ?', params.user_id) }}"
|
|
561
|
+
```
|
|
562
|
+
|
|
563
|
+
### Docker Usage
|
|
564
|
+
|
|
565
|
+
```dockerfile
|
|
566
|
+
# Dockerfile
|
|
567
|
+
FROM python:3.11-slim
|
|
568
|
+
|
|
569
|
+
WORKDIR /app
|
|
570
|
+
COPY requirements.txt .
|
|
571
|
+
RUN pip install -r requirements.txt
|
|
572
|
+
|
|
573
|
+
COPY . .
|
|
574
|
+
EXPOSE 8000
|
|
575
|
+
|
|
576
|
+
CMD ["api-mocker", "start", "--config", "config.yaml", "--host", "0.0.0.0"]
|
|
577
|
+
```
|
|
578
|
+
|
|
579
|
+
```yaml
|
|
580
|
+
# docker-compose.yml
|
|
581
|
+
version: '3.8'
|
|
582
|
+
services:
|
|
583
|
+
api-mocker:
|
|
584
|
+
build: .
|
|
585
|
+
ports:
|
|
586
|
+
- "8000:8000"
|
|
587
|
+
volumes:
|
|
588
|
+
- ./config:/app/config
|
|
589
|
+
environment:
|
|
590
|
+
- DEBUG=true
|
|
591
|
+
```
|
|
592
|
+
|
|
593
|
+
### CI/CD Integration
|
|
594
|
+
|
|
595
|
+
```yaml
|
|
596
|
+
# .github/workflows/test.yml
|
|
597
|
+
name: Test API Mocks
|
|
598
|
+
|
|
599
|
+
on: [push, pull_request]
|
|
600
|
+
|
|
601
|
+
jobs:
|
|
602
|
+
test:
|
|
603
|
+
runs-on: ubuntu-latest
|
|
604
|
+
steps:
|
|
605
|
+
- uses: actions/checkout@v3
|
|
606
|
+
- uses: actions/setup-python@v4
|
|
607
|
+
with:
|
|
608
|
+
python-version: '3.11'
|
|
609
|
+
|
|
610
|
+
- name: Install dependencies
|
|
611
|
+
run: |
|
|
612
|
+
pip install api-mocker
|
|
613
|
+
pip install pytest requests
|
|
614
|
+
|
|
615
|
+
- name: Run tests
|
|
616
|
+
run: |
|
|
617
|
+
api-mocker test --config config.yaml --test-file tests.yaml
|
|
618
|
+
```
|
|
619
|
+
|
|
620
|
+
## 🔧 Development
|
|
621
|
+
|
|
622
|
+
### Setup Development Environment
|
|
623
|
+
```bash
|
|
624
|
+
git clone https://github.com/your-username/api-mocker.git
|
|
625
|
+
cd api-mocker
|
|
626
|
+
python -m venv venv
|
|
627
|
+
source venv/bin/activate # On Windows: venv\Scripts\activate
|
|
628
|
+
pip install -e ".[dev]"
|
|
629
|
+
```
|
|
630
|
+
|
|
631
|
+
### Run Tests
|
|
632
|
+
```bash
|
|
633
|
+
pytest tests/
|
|
634
|
+
```
|
|
635
|
+
|
|
636
|
+
### Build Package
|
|
637
|
+
```bash
|
|
638
|
+
python -m build
|
|
639
|
+
```
|
|
640
|
+
|
|
641
|
+
## 🤝 Contributing
|
|
642
|
+
|
|
643
|
+
Contributions are welcome! Please see [CONTRIBUTING.md](CONTRIBUTING.md) for guidelines.
|
|
644
|
+
|
|
645
|
+
## 📄 License
|
|
646
|
+
|
|
647
|
+
MIT License - see [LICENSE](LICENSE) file for details.
|
|
648
|
+
|
|
649
|
+
## 🆘 Support
|
|
650
|
+
|
|
651
|
+
- 📖 [Documentation](https://github.com/your-username/api-mocker#documentation)
|
|
652
|
+
- 🐛 [Issue Tracker](https://github.com/your-username/api-mocker/issues)
|
|
653
|
+
- 💬 [Discussions](https://github.com/your-username/api-mocker/discussions)
|
|
654
|
+
|
|
655
|
+
---
|
|
656
|
+
|
|
657
|
+
© 2025 sherin joseph roy
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
api_mocker/__init__.py,sha256=CFC641XJCw_2RbFocNHCTwfr3EEdOQmICFGG_Xlny3Y,168
|
|
2
2
|
api_mocker/cli.py,sha256=LktBFt7V7c1Y00zwZuZzjD5ktAJsm31S7BAaiiGkg5g,19485
|
|
3
3
|
api_mocker/config.py,sha256=zNlJCk1Bs0BrGU-92wiFv2ZTBRu9dJQ6sF8Dh6kIhLQ,913
|
|
4
|
-
api_mocker/core.py,sha256=
|
|
4
|
+
api_mocker/core.py,sha256=K3rP5_cJIEpr02Qgcc_n1Ga3KPo4HumsA6Dlynaj_nQ,8478
|
|
5
5
|
api_mocker/openapi.py,sha256=Pb1gKbBWosEV5i739rW0Nb3ArNq62lgMN0ecyvigNKY,7403
|
|
6
6
|
api_mocker/plugins.py,sha256=OK3OVHJszDky46JHntMVsZUH1ajBjBhAKq3TCDYuxWI,8178
|
|
7
7
|
api_mocker/recorder.py,sha256=7tiT2Krxy3nLDxFAE7rpZSimuD-rKeiwdU72cp0dg6E,9984
|
|
8
8
|
api_mocker/server.py,sha256=xfczRj4xFXGVaGn2pVPgGvYyv3IHUlYTEz3Hop1KQu0,3812
|
|
9
|
-
api_mocker-0.1.
|
|
10
|
-
api_mocker-0.1.
|
|
11
|
-
api_mocker-0.1.
|
|
12
|
-
api_mocker-0.1.
|
|
13
|
-
api_mocker-0.1.
|
|
14
|
-
api_mocker-0.1.
|
|
9
|
+
api_mocker-0.1.2.dist-info/licenses/LICENSE,sha256=FzyeLcPe623lrwpFx3xQ3W0Hb_S2sbHqLzhSXaTmcGg,1074
|
|
10
|
+
api_mocker-0.1.2.dist-info/METADATA,sha256=eKgFL9qDexZOltj-wBi_PYAhw0zAL8i-M76IW8GTBpY,15401
|
|
11
|
+
api_mocker-0.1.2.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
12
|
+
api_mocker-0.1.2.dist-info/entry_points.txt,sha256=dj0UIkQ36Uq3oeSjGzmRRUQKFriq4WMCzg7TCor7wkM,51
|
|
13
|
+
api_mocker-0.1.2.dist-info/top_level.txt,sha256=ZcowEudKsJ6xbvOXIno2zZcPhjB-gGO1w7uzoUKRKDM,11
|
|
14
|
+
api_mocker-0.1.2.dist-info/RECORD,,
|
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
Metadata-Version: 2.4
|
|
2
|
-
Name: api-mocker
|
|
3
|
-
Version: 0.1.0
|
|
4
|
-
Summary: The industry-standard, production-ready, free API mocking and development acceleration tool.
|
|
5
|
-
Author-email: sherin joseph roy <sherin.joseph2217@gmail.com>
|
|
6
|
-
License: MIT License
|
|
7
|
-
|
|
8
|
-
Copyright (c) 2024 sherin joseph roy
|
|
9
|
-
|
|
10
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
11
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
12
|
-
in the Software without restriction, including without limitation the rights
|
|
13
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
14
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
15
|
-
furnished to do so, subject to the following conditions:
|
|
16
|
-
|
|
17
|
-
The above copyright notice and this permission notice shall be included in all
|
|
18
|
-
copies or substantial portions of the Software.
|
|
19
|
-
|
|
20
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
21
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
22
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
23
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
24
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
25
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
26
|
-
SOFTWARE.
|
|
27
|
-
Project-URL: Homepage, https://github.com/Sherin-SEF-AI/api-mocker
|
|
28
|
-
Project-URL: Repository, https://github.com/Sherin-SEF-AI/api-mocker.git
|
|
29
|
-
Keywords: api,mock,mocking,development,testing,openapi,swagger,cli,devops
|
|
30
|
-
Classifier: Programming Language :: Python :: 3
|
|
31
|
-
Classifier: License :: OSI Approved :: MIT License
|
|
32
|
-
Classifier: Operating System :: OS Independent
|
|
33
|
-
Classifier: Development Status :: 3 - Alpha
|
|
34
|
-
Classifier: Intended Audience :: Developers
|
|
35
|
-
Classifier: Topic :: Software Development :: Testing
|
|
36
|
-
Classifier: Topic :: Software Development :: Libraries :: Application Frameworks
|
|
37
|
-
Requires-Python: >=3.8
|
|
38
|
-
Description-Content-Type: text/markdown
|
|
39
|
-
License-File: LICENSE
|
|
40
|
-
Requires-Dist: typer>=0.9.0
|
|
41
|
-
Requires-Dist: fastapi>=0.100.0
|
|
42
|
-
Requires-Dist: uvicorn>=0.23.0
|
|
43
|
-
Requires-Dist: PyYAML>=6.0
|
|
44
|
-
Requires-Dist: toml>=0.10.2
|
|
45
|
-
Requires-Dist: pytest>=7.0.0
|
|
46
|
-
Requires-Dist: httpx>=0.24.0
|
|
47
|
-
Requires-Dist: rich>=13.0.0
|
|
48
|
-
Dynamic: license-file
|
|
49
|
-
|
|
50
|
-
# api-mocker
|
|
51
|
-
|
|
52
|
-
The industry-standard, production-ready, free API mocking and development acceleration tool.
|
|
53
|
-
|
|
54
|
-
## Project Mission
|
|
55
|
-
Create the most comprehensive, user-friendly, and feature-rich API mocking solution to eliminate API dependency bottlenecks and accelerate development workflows for all developers.
|
|
56
|
-
|
|
57
|
-
## Features
|
|
58
|
-
- Robust HTTP mock server supporting all HTTP methods
|
|
59
|
-
- Dynamic and static response generation
|
|
60
|
-
- OpenAPI/Swagger/Postman import/export
|
|
61
|
-
- CLI and Python API interfaces
|
|
62
|
-
- Hot-reloading, config file support (JSON/YAML/TOML)
|
|
63
|
-
- Request recording, replay, and proxy mode
|
|
64
|
-
- Schema-based data generation and validation
|
|
65
|
-
- Advanced routing, middleware, and authentication simulation
|
|
66
|
-
- Data persistence, state management, and in-memory DB
|
|
67
|
-
- Performance, monitoring, and analytics tools
|
|
68
|
-
- Framework integrations (Django, Flask, FastAPI, Node.js, etc.)
|
|
69
|
-
- Docker, CI/CD, and cloud deployment support
|
|
70
|
-
- Team collaboration and plugin architecture
|
|
71
|
-
|
|
72
|
-
## Installation
|
|
73
|
-
```bash
|
|
74
|
-
pip install api-mocker
|
|
75
|
-
```
|
|
76
|
-
|
|
77
|
-
## Quick Start
|
|
78
|
-
```bash
|
|
79
|
-
api-mocker start --config api-mock.yaml
|
|
80
|
-
```
|
|
81
|
-
Or use as a Python library:
|
|
82
|
-
```python
|
|
83
|
-
from api_mocker import MockServer
|
|
84
|
-
server = MockServer(config_path="api-mock.yaml")
|
|
85
|
-
server.start()
|
|
86
|
-
```
|
|
87
|
-
|
|
88
|
-
## Documentation
|
|
89
|
-
See [Full Documentation](https://github.com/Sherin-SEF-AI/api-mocker#documentation) for guides, API reference, and examples.
|
|
90
|
-
|
|
91
|
-
## Contributing
|
|
92
|
-
Contributions are welcome! Please see [CONTRIBUTING.md](CONTRIBUTING.md) for guidelines.
|
|
93
|
-
|
|
94
|
-
## License
|
|
95
|
-
MIT License
|
|
96
|
-
|
|
97
|
-
---
|
|
98
|
-
© 2024 sherin joseph roy
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|