summaryrefslogtreecommitdiffstats
path: root/docs/en/cowboy/1.0/guide/modern_web/index.html
blob: 530a5af07a69b4bac10bf537e792ca45d471e073 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <title>Nine Nines Support: Cowboy User Guide</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <!-- Change them or set them up as you like -->
    <meta name="description" content="">
    <meta name="author" content="(Soft10) Pol Cámara">

    <!-- Stylesheets -->    
    <link href='http://fonts.googleapis.com/css?family=Open+Sans:400,700,400italic' rel='stylesheet' type='text/css'>
    <link href="/css/bootstrap.min.css" rel="stylesheet">
    <link href="/css/99s.css" rel="stylesheet">
<!--    <link href="js/google-code-prettify/prettify.css" rel="stylesheet"> -->
    <link href="/css/sh99s.css"  rel="stylesheet"/>

    <!-- Enables html5 support on older browsers, other js is placed at the end of the page to speed up loading -->
    <!--[if lt IE 9]>
      <script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
    <![endif]-->

    <link rel="shortcut icon" href="/img/ico/favicon.ico">
    <link rel="apple-touch-icon-precomposed" sizes="114x114" href="/img/ico/apple-touch-icon-114.png">
    <link rel="apple-touch-icon-precomposed" sizes="72x72" href="/img/ico/apple-touch-icon-72.png">
    <link rel="apple-touch-icon-precomposed" href="/img/ico/apple-touch-icon-57.png">
	<link rel="alternate" href="/feeds/atom.xml" type="application/atom+xml" title="Nine Nines Atom Feed">
  </head>

  <body class="big_text docs">
    <header id="page-head">
      <div id="topbar" class="container">
          <div class="row">
            <div class="span2">
              <h1 id="logo"><a href="/" title="99s">99s</a></h1>
            </div>
            <div class="span10">
              <!-- Top navigation and social icons-->
              <div id="side-header">
                <nav>
                  <ul>
					<li><a title="Erlang training" href="/training">Training</a></li>
                    <li><a title="Technical publications" href="/articles">Articles</a></li>
					<li><a title="Our talks" href="/talks">Talks</a></li>
					<li class="active"><a title="Our services" href="/support">Pricing &amp; Sponsoring</a></li>
					<li><a title="Community support" href="https://ninenines.eu/archives/extend/">Mailing Lists</a></li>
                    <li><a title="Contact us" href="mailto:[email protected]">Contact</a></li>
                  </ul>
                </nav> 
                <ul id="social">
                  <li>
                    <a href="https://github.com/ninenines" title="Check our Github repositories"><img src="/img/ico_github.png" data-hover="/img/ico_github_alt.png" alt="Github"></a>
                  </li>
                  <li class="dropdown" id="twitter-links">
                    <a href="#twitter-links" class="dropdown-toggle" data-toggle="dropdown"  title="Follow us on Twitter">
                        <img src="/img/ico_microblog.png" data-hover="/img/ico_microblog_alt.png" alt="Twitter">
                    </a>                 
                    <ul class="dropdown-menu">
                      <li><a title="Visit Loïc Hoguin's Twitter Account" href="http://twitter.com/lhoguin">@lhoguin</a></li>
                      <!-- <li class="divider"></li>
                      <li><a title="Visit our official Twitter account" href="#">@99s</a></li> -->
                    </ul>
                  </li>
                  <!-- <li>
                    <a href="/css/" title="Add us on Linkedin"><img src="/img/ico_linkedin.png" data-hover="img/ico_linkedin_alt.png" alt="Linkedin"></a>
                  </li> -->
                </ul>
              </div>
            </div>
          </div>
      </div>


    </header>


<div id="contents" class="two_col">
<div class="container">
<div class="row">
<div id="docs" class="span9 maincol">

<h1 class="lined-header"><span>The modern Web</span></h1>

<p>Let's take a look at various technologies from the beginnings of the Web up to this day, and get a preview of what's coming next.</p>

<p>Cowboy is compatible with all the technology cited in this chapter except of course HTTP/2.0 which has no implementation in the wild at the time of writing.</p>

<h2 id="the_prehistoric_web">The prehistoric Web</h2>

<p>HTTP was initially created to serve HTML pages and only had the GET method for retrieving them. This initial version is documented and is sometimes called HTTP/0.9. HTTP/1.0 defined the GET, HEAD and POST methods, and was able to send data with POST requests.</p>

<p>HTTP/1.0 works in a very simple way. A TCP connection is first established to the server. Then a request is sent. Then the server sends a response back and closes the connection.</p>

<p>Suffice to say, HTTP/1.0 is not very efficient. Opening a TCP connection takes some time, and pages containing many assets load much slower than they could because of this.</p>

<p>Most improvements done in recent years focused on reducing this load time and reducing the latency of the requests.</p>

<h2 id="http/1.1">HTTP/1.1</h2>

<p>HTTP/1.1 quickly followed and added a keep-alive mechanism to allow using the same connection for many requests, as well as streaming capabilities, allowing an endpoint to send a body in well defined chunks.</p>

<p>HTTP/1.1 defines the OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE and CONNECT methods. The PATCH method was added in more recent years. It also improves the caching capabilities with the introduction of many headers.</p>

<p>HTTP/1.1 still works like HTTP/1.0 does, except the connection can be kept alive for subsequent requests. This however allows clients to perform what is called as pipelining: sending many requests in a row, and then processing the responses which will be received in the same order as the requests.</p>

<h2 id="rest">REST</h2>

<p>The design of HTTP/1.1 was influenced by the REST architectural style. REST, or REpresentational State Transfer, is a style of architecture for loosely connected distributed systems.</p>

<p>REST defines constraints that systems must obey to in order to be RESTful. A system which doesn't follow all the constraints cannot be considered RESTful.</p>

<p>REST is a client-server architecture with a clean separation of concerns between the client and the server. They communicate by referencing resources. Resources can be identified, but also manipulated. A resource representation has a media type and information about whether it can be cached and how. Hypermedia determines how resources are related and how they can be used. REST is also stateless. All requests contain the complete information necessary to perform the action.</p>

<p>HTTP/1.1 defines all the methods, headers and semantics required to implement RESTful systems.</p>

<p>REST is most often used when designing web application APIs which are generally meant to be used by executable code directly.</p>

<h2 id="xmlhttprequest">XmlHttpRequest</h2>

<p>Also know as AJAX, this technology allows Javascript code running on a web page to perform asynchronous requests to the server. This is what started the move from static websites to dynamic web applications.</p>

<p>XmlHttpRequest still performs HTTP requests under the hood, and then waits for a response, but the Javascript code can continue to run until the response arrives. It will then receive the response through a callback previously defined.</p>

<p>This is of course still requests initiated by the client, the server still had no way of pushing data to the client on its own, so new technology appeared to allow that.</p>

<h2 id="long-polling">Long-polling</h2>

<p>Polling was a technique used to overcome the fact that the server cannot push data directly to the client. Therefore the client had to repeatedly create a connection, make a request, get a response, then try again a few seconds later. This is overly expensive and adds an additional delay before the client receives the data.</p>

<p>Polling was necessary to implement message queues and other similar mechanisms, where a user must be informed of something when it happens, rather than when he refreshes the page next. A typical example would be a chat application.</p>

<p>Long-polling was created to reduce the server load by creating less connections, but also to improve latency by getting the response back to the client as soon as it becomes available on the server.</p>

<p>Long-polling works in a similar manner to polling, except the request will not get a response immediately. Instead the server leaves it open until it has a response to send. After getting the response, the client creates a new request and gets back to waiting.</p>

<p>You probably guessed by now that long-polling is a hack, and like most hacks it can suffer from unforeseen issues, in this case it doesn't always play well with proxies.</p>

<h2 id="html5">HTML5</h2>

<p>HTML5 is, of course, the HTML version after HTML4. But HTML5 emerged to solve a specific problem: dynamic web applications.</p>

<p>HTML was initially created to write web pages which compose a website. But soon people and companies wanted to use HTML to write more and more complex websites, eventually known as web applications. They are for example your news reader, your email client in the browser, or your video streaming website.</p>

<p>Because HTML wasn't enough, they started using proprietary solutions, often implemented using plug-ins. This wasn't perfect of course, but worked well enough for most people.</p>

<p>However, the needs for a standard solution eventually became apparent. The browser needed to be able to play media natively. It needed to be able to draw anything. It needed an efficient way of streaming events to the server, but also receiving events from the server.</p>

<p>The solution went on to become HTML5. At the time of writing it is being standardized.</p>

<h2 id="eventsource">EventSource</h2>

<p>EventSource, sometimes also called Server-Sent Events, is a technology allowing servers to push data to HTML5 applications.</p>

<p>EventSource is one-way communication channel from the server to the client. The client has no means to talk to the server other than by using HTTP requests.</p>

<p>It consists of a Javascript object allowing setting up an EventSource connection to the server, and a very small protocol for sending events to the client on top of the HTTP/1.1 connection.</p>

<p>EventSource is a lightweight solution that only works for UTF-8 encoded text data. Binary data and text data encoded differently are not allowed by the protocol. A heavier but more generic approach can be found in Websocket.</p>

<h2 id="websocket">Websocket</h2>

<p>Websocket is a protocol built on top of HTTP/1.1 that provides a two-ways communication channel between the client and the server. Communication is asynchronous and can occur concurrently.</p>

<p>It consists of a Javascript object allowing setting up a Websocket connection to the server, and a binary based protocol for sending data to the server or the client.</p>

<p>Websocket connections can transfer either UTF-8 encoded text data or binary data. The protocol also includes support for implementing a ping/pong mechanism, allowing the server and the client to have more confidence that the connection is still alive.</p>

<p>A Websocket connection can be used to transfer any kind of data, small or big, text or binary. Because of this Websocket is sometimes used for communication between systems.</p>

<h2 id="spdy">SPDY</h2>

<p>SPDY is an attempt to reduce page loading time by opening a single connection per server, keeping it open for subsequent requests, and also by compressing the HTTP headers to reduce the size of requests.</p>

<p>SPDY is compatible with HTTP/1.1 semantics, and is actually just a different way of performing HTTP requests and responses, by using binary frames instead of a text-based protocol. SPDY also allows the server to send extra responses following a request. This is meant to allow sending the resources associated with the request before the client requests them, saving latency when loading websites.</p>

<p>SPDY is an experiment that has proven successful and is used as the basis for the HTTP/2.0 standard.</p>

<p>Browsers make use of TLS Next Protocol Negotiation to upgrade to a SPDY connection seamlessly if the protocol supports it.</p>

<p>The protocol itself has a few shortcomings which are being fixed in HTTP/2.0.</p>

<h2 id="http/2.0">HTTP/2.0</h2>

<p>HTTP/2.0 is the long-awaited update to the HTTP/1.1 protocol. It is based on SPDY although a lot has been improved at the time of writing.</p>

<p>HTTP/2.0 is an asynchronous two-ways communication channel between two endpoints.</p>

<p>It is planned to be ready late 2014.</p>


<!-- a.code -->
</div>

<div class="span3 sidecol">
<div class="input-append">
<form id="form-search" class="form-search" action="#">
	<input id="input-search" type="text" placeholder="Function search" autocomplete="off" autofocus class="input-medium search-query span2">
	<button type="submit" class="btn btn-success">Go</button>
</form>
</div>

<h3 id="docs-nav">Navigation</h3>

<h3>See also</h3><ul><li><a href="/docs/en/cowboy/1.0/manual/">Function Reference</a></li><li><a href="/docs/en/cowboy/1.0/index.html">README</a></li></ul>

<h3>Version select</h3>
<ul>

	<li><a href="/docs/en/cowboy/1.0/guide/"><strong>1.0</strong></a></li>

	<li><a href="/docs/en/cowboy/HEAD/guide/"><strong>HEAD</strong></a></li>

</ul>

</div>
</div>
</div>
</div>


      <footer>
        <div class="container">
          <div class="row">
            <div class="span6">
              <p id="scroll-top"><a href="#">↑ Scroll to top</a></p>
              <nav>
                <ul>
                  <li><a href="mailto:[email protected]" title="Contact us">Contact us</a></li><li><a href="https://github.com/ninenines/ninenines.github.io" title="Github repository">Contribute to this site</a></li>
                </ul>
              </nav>
            </div>
            <div class="span6 credits">
               <p><img src="/img/footer_logo.png"></p>
               <p>Copyright &copy; Nine Nines 2012-2014</p>
            </div>
          </div>
        </div>
      </footer>

    <!-- Javascript -->
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
    <script src="/js/bootstrap-carousel.js"></script>
    <script src="/js/bootstrap-dropdown.js"></script>
    <script src="/js/custom.js"></script>


<script type="text/javascript" src="/js/shCore.js"></script>
<script type="text/javascript" src="/js/shlang/shBrushBash.js"></script>
<script type="text/javascript" src="/js/shlang/shBrushErlang.js"></script>
<script type="text/javascript" src="/js/shlang/shBrushJScript.js"></script>
<script type="text/javascript" src="/js/shlang/shBrushPlain.js"></script>
<script type="text/javascript">SyntaxHighlighter.all();</script>

<script type="text/javascript" src="/js/fuse.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
	var f;

	$.getJSON("/docs/db.json", function(data){
		f = new Fuse(data, {keys: ["n"], threshold: 0.3});
		$("<ul id=\"search-results\">").insertAfter("#form-search");
	});

	$("#input-search").keyup(function(e){if(f){if (e.which != 13 ){
		var results = f.search($(this).val());
		if (results.length == 0){
			$("#form-search").attr("action", "#");
		}else{
			$("#form-search").attr("action", results[0].l);
		}

		$("#search-results").empty();
		for (var i = 0; i < 10 && i < results.length; i++){
			$("<li><a href=\"" + results[i].l + "\">" + results[i].n + "</a></li>")
				.appendTo("#search-results");
		}
	}}});
});
</script>

  </body>
</html>