i woud like to build a small python HTTP server that givent GET /helloWorld return me a…
- User
i woud like to build a small python HTTP server that givent GET /helloWorld return me a JSON with 2 fields message = "Bonjour" who="you"
Assistant
Here's a simple Python HTTP server that will respond with the desired JSON when a GET request is made to the URL
/helloWorld.import json from http.server import BaseHTTPRequestHandler, HTTPServer class JSONServerHandler(BaseHTTPRequestHandler): def do_GET(self): if self.path == '/helloWorld': response_data = json.dumps({"message": "Bonjour", "who": "you"}) self.send_response(200) self.send_header('Content-type', 'application/json') self.end_headers() self.wfile.write(bytes(response_data, 'utf-8')) else: self.send_error(404, "Not Found") if __name__ == '__main__': server_address = ('', 8000) httpd = HTTPServer(server_address, JSONServerHandler) print("Starting HTTP server on port 8000...") httpd.serve_forever()
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.