scratch/content/html/en/blog/mvc/mvc2.md
2010-03-12 13:49:27 +01:00

1.3 KiB

filters_pre kind menupriority title multiTitle
bluecloth
article 2 MVC explained (Let's code it)
fr en
let's code it Let's code it

the purpose of this part is to code the webserver part of your application. Some really complete framework already exists for that.

newcorps

Let's code it

You choose a programming language (for readability I choosen Ruby).

First you use a simple HTTP Server library (for simplicity I choosen webrick)

Here an example of a very minimal HTTP Server. When it receives a GET request at the port number 2000 at the directory '/' it returns:

<html>Content</html>

Here is the code:

#!/usr/bin/env ruby require 'webrick' include WEBrick s = HTTPServer.new( :Port => 2000 )

class HelloServlet < HTTPServlet::AbstractServlet def do_GET(req, res) res.body = '<html>Content</html>' res['Content-Type'] = "text/html" end end

s.mount("/", HelloServlet) s.start

You can try it yourself starting by downloading and starting the ruby program and clicking this link (http://localhost:2000) (You must start the server for this link to work).

I Believe what it does is mostly straightforward