To create an HTTP server in Ruby, we can use the built-in WEBrick
library. Here is an example of creating a HTTP server and parsing the POST request body as form data:
main.rb487 chars26 lines
In this example, we create a HTTP server and mount a block to handle the requests. Inside the block, we first check if the request method is POST. If it is, we parse the request body as form data using the URI.decode_www_form
method. Then we print the form data and set the response body to confirm that the form data was received.
To start the server, we simply call server.start
. The server will listen on port 8000 by default.
gistlibby LogSnag