🔧 Objective: Learn to set up a basic HTTP server that responds to GET requests.
🌐 Note: This guide assumes you're using Python 3. If you're on another platform, check out our tutorial on handling GET requests for more details.


Step-by-Step Guide

  1. Install Dependencies
    For Python, no installation is needed—use the built-in http.server module.
    For Node.js, run:

    npm install express
    
  2. Write Server Code
    Here's a minimal Python example:

    from http.server import BaseHTTPRequestHandler, HTTPServer
    
    class SimpleServer(BaseHTTPRequestHandler):
        def do_GET(self):
            self.send_response(200)
            self.send_header('Content-type', 'text/html')
            self.end_headers()
            self.wfile.write(b'Hello, World!')
    
    if __name__ == '__main__':
        server = HTTPServer(('localhost', 8000), SimpleServer)
        print('Server running on port 8000...')
        server.serve_forever()
    
  3. Run the Server
    Execute the script and navigate to http://localhost:8000 in your browser. 🌐


Tips & Extensions

  • 📌 To handle more complex routes, explore the HTTP methods tutorial.
  • 🧪 Test your server with tools like Postman or curl for advanced scenarios.

http_server
📌 **Pro Tip**: Use `curl http://localhost:8000` in the terminal to verify your server's response. 🐧