57 lines
1.3 KiB
Markdown
57 lines
1.3 KiB
Markdown
|
-----
|
||
|
# Built-in
|
||
|
filters_pre:
|
||
|
- "bluecloth"
|
||
|
|
||
|
# Custom
|
||
|
kind: article
|
||
|
menupriority: 2
|
||
|
title: MVC explained (Let's code it)
|
||
|
multiTitle:
|
||
|
fr: let's code it
|
||
|
en: 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:
|
||
|
|
||
|
<div><code class="html"><html>Content</html></code></div>
|
||
|
|
||
|
Here is the code:
|
||
|
|
||
|
<div>
|
||
|
<code class="ruby" file="minimalHttpServer.rb">
|
||
|
#!/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 </code>
|
||
|
</div>
|
||
|
|
||
|
You can try it yourself starting by downloading and starting the ruby program and clicking this [link (http://localhost:2000)](http://localhost:2000/) (You must start the server for this link to work).
|
||
|
|
||
|
I Believe what it does is mostly straightforward
|