Download presentation
Presentation is loading. Please wait.
Published byAbraham Welch Modified over 9 years ago
1
Philip Repsher October 29 th, 2008 Or Maybe November 3 rd, 2008
2
In this presentation, I will guide you through how to create a simple ruby web server and a simple ruby web client to get information from the server. Webrick Simplified web server library included in ruby since Ruby 1.8.0 net/http class Basic Ruby framework for HTTP interaction, we will use it for our client.
3
Webrick is a library included in the Ruby standard library dedicated to creating HTTP servers Webrick is a very easy way to create HTTP servers. A few commands - Require “webrick” WEBrick::HTTPServer.new(address, port) Trap “INT” Let’s go make a simple web server now
4
The server we just made doesn’t truly do anything After creating a server, servlets are mounted onto the server as subdirectories (www.server.com/servlet) to provide more functionality Each time a servlet is called, Ruby creates a new instance of the servlet in its own thread and runs it.
5
Mount – after you make a servlet, it must be mounted on the server before the server is started. do_GET – A method with this name will service all GET requests. do_GET methods have two arguments, the request and the response, or req and resp. Let’s make some servlets!
6
Webrick comes installed with several useful Servlets Filehandler – if the server is fed a path when starting it automatically sets up a filehandler to serve that directory CGIhandler-If the directory a filehandler is set up for contains any CGI files, the server will automatically set up a CGIhandler to handle the execution of these files.
7
Net/http is a ruby class that provides access to World Wide Web documents and information via HTTP. As such, it is the class to use to make a client that will access the web server and report back. Require ‘net/http’
8
Next we need to set up the client. This client will send a request to the server for info, and then print the info out when it is received. This client also needs to include the uri library to parse the URL for the net/http command. We could also add some time commands to see how long the get takes.
9
There are many more advanced Ruby server frameworks out there In Particular, Ruby on Rails is very popular Ruby on Rails is a Ruby development framework set up to assist in the making of ruby web applications, particularly database driven ones.
10
http://segment7.net/projects/ruby/WEBrick/ servlets.html http://segment7.net/projects/ruby/WEBrick/ servlets.html http://microjet.ath.cx/webrickguide/html/ht ml_webrick.html http://microjet.ath.cx/webrickguide/html/ht ml_webrick.html http://www.ruby- doc.org/stdlib/libdoc/net/http/rdoc/index.ht ml http://www.ruby- doc.org/stdlib/libdoc/net/http/rdoc/index.ht ml http://www.webrick.org/ http://www.webrick.org/ http://www.ruby- doc.org/docs/ProgrammingRuby/ http://www.ruby- doc.org/docs/ProgrammingRuby/
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.