HTTP Mock Generator
Generate mock HTTP response templates with status codes, headers, and body for testing.
Questions Fréquentes
Implémentation du Code
import json
from http.server import HTTPServer, BaseHTTPRequestHandler
class MockHandler(BaseHTTPRequestHandler):
def do_GET(self):
# Customize: status code, headers, and body
status_code = 200
response_body = json.dumps({"message": "Mock response", "status": "ok"})
self.send_response(status_code)
self.send_header("Content-Type", "application/json")
self.send_header("Content-Length", str(len(response_body)))
self.send_header("X-Request-Id", "mock-12345")
self.end_headers()
self.wfile.write(response_body.encode())
def log_message(self, format, *args):
pass # Suppress default logging
if __name__ == "__main__":
server = HTTPServer(("localhost", 8080), MockHandler)
print("Mock server running on http://localhost:8080")
server.serve_forever()Comments & Feedback
Comments are powered by Giscus. Sign in with GitHub to leave a comment.