main.rb479 chars20 lines
This code creates a TCP server that listens on port 8080 on localhost
. When a client connects to the server, the server accepts the connection, reads the HTTP request sent by the client, prints the request line to console and then closes the client socket.
To implement a specific route such as a GET
request for the /hello
path, you can modify the code as follows:
main.rb932 chars29 lines
This code checks the HTTP method and path from the request line, sends a successful HTTP response with "Hello, World!" as the response body when the request is a GET
request for the /hello
path, and sends a not found HTTP response with a "404 Not Found" message when the request is for a different path or HTTP method.
gistlibby LogSnag