To create a basic HTTP server that reads the request body as text in Ruby, you can use the built-in WEBrick
module. Here's an example:
main.rb738 chars28 lines
This code defines a custom RequestHandler
class that logs the request body to the console and sends a response back to the client including the received body. The server listens on port 8000 and mounts the custom handler to the root path. When a POST
request is made to the server, the handler is called and the request body is read as text. Finally, the server is started and will continue to run until terminated.
gistlibby LogSnag