1 / 10

Ruby Web

Ruby Web. Philip Repsher October 29 th , 2008 Or Maybe November 3 rd , 2008. Intro. 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

indra
Download Presentation

Ruby Web

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Ruby Web Philip Repsher October 29th, 2008 Or Maybe November 3rd, 2008

  2. Intro • 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 • 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. Webrick Servers/Servlets • 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. Things to Know - Servlets • 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 Standard Servlets • 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 • 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. Net/http Client • 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. Advanced Ruby Web • 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. Resources • http://segment7.net/projects/ruby/WEBrick/servlets.html • http://microjet.ath.cx/webrickguide/html/html_webrick.html • http://www.ruby-doc.org/stdlib/libdoc/net/http/rdoc/index.html • http://www.webrick.org/ • http://www.ruby-doc.org/docs/ProgrammingRuby/

More Related