-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathgetting-started.html
131 lines (95 loc) · 5.18 KB
/
getting-started.html
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
<!DOCTYPE html>
<html>
<head>
<meta charset='utf-8'>
<meta http-equiv="X-UA-Compatible" content="chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<link href='http://fonts.googleapis.com/css?family=Raleway' rel='stylesheet' type='text/css'>
<link rel="stylesheet" type="text/css" href="stylesheets/stylesheet.css" media="screen" />
<link rel="stylesheet" type="text/css" href="stylesheets/pygment_trac.css" media="screen" />
<link rel="stylesheet" type="text/css" href="stylesheets/print.css" media="print" />
<link rel="stylesheet" type="text/css" href="stylesheets/highlight_default.css" media="all" />
<script src="javascripts/highlight.pack.js"></script>
<script src="javascripts/main.js"></script>
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-52880198-1', 'auto');
ga('send', 'pageview');
</script>
<!--[if lt IE 9]>
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<title>nickel.rs - Getting Started</title>
</head>
<body>
<header>
<div class="inner">
<h1>nickel.rs</h1>
<h2>web application framework for rust</h2>
<div class="header-buttons">
<iframe src="http://ghbtns.com/github-btn.html?user=nickel-org&repo=nickel.rs&type=watch&count=true&size=large"
allowtransparency="true" frameborder="0" scrolling="0" width="130" height="30"></iframe>
<a href="/" class="button">Home</a>
<a href="https://docs.rs/nickel/" class="button">API docs</a>
</div>
</div>
</header>
<div id="content-wrapper">
<div class="inner clearfix">
<section id="main-content">
<h1>
<a name="welcome-to-github-pages" class="anchor" href="#welcome-to-github-pages"><span class="octicon octicon-link"></span></a>Getting Started</h1>
<p>Getting started with nickel.rs is extremely easy. This guide will walk you through the steps necessary to write your first nickel app.</p>
<h3>
<a name="designer-templates" class="anchor" href="#designer-templates"><span class="octicon octicon-link"></span></a>1. Get a recent version of Rust and Cargo</h3>
<p>In order to write a nickel app you first need to make sure to have a recent version of Rust and <a href="http://crates.io/">Cargo</a>. In case you are wondering Cargo is the package manager for Rust. It makes dependency and build management a breeze. The easiest way to install both is just a simple one liner on your shell.</p>
<pre><code>$ curl -s https://static.rust-lang.org/rustup.sh | sudo sh
</code></pre>
<h3>
<a name="designer-templates" class="anchor" href="#designer-templates"><span class="octicon octicon-link"></span></a>2. Let Cargo generate a new project directory and <code>cd</code> into it</h3>
<pre><code>$ cargo new nickel-demo --bin && cd nickel-demo</code></pre>
By feeding <code>--bin</code> to the <code>cargo new</code> we command cargo to choose the project folder layout for programs instead of libraries. This will also make sure that we can later just use <code>cargo run</code> to start the program.
<h3>
<a name="designer-templates" class="anchor" href="#designer-templates"><span class="octicon octicon-link"></span></a>3. Edit the generated <code>Cargo.toml</code> file</h3>
<p>The <code>Cargo.toml</code> file is the manifest that describes all dependencies of your app and also tells Cargo how to build the project. Just append the following to the file to make Cargo aware of the nickel.rs dependency.</p>
<pre><code>
[dependencies]
nickel = "*"
</code></pre>
By now your <code>Cargo.toml</code> file should look like this:
<pre><code>
[package]
name = "my-demo"
version = "0.0.1"
authors = ["Your Name <[email protected]>"]
[dependencies]
nickel = "*"
</code></pre>
<h3>
<a name="designer-templates" class="anchor" href="#designer-templates"><span class="octicon octicon-link"></span></a>4. Edit the generated <code>main.rs</code> file</h3>
<p>Cargo generated a <code>main.rs</code> in the <code>src</code> directory of your project. It comes predefined with a hello world implementation. This is where we will put the code for your first nickel app. Delete the content and overwrite it with this:
</p>
<pre><code>
#[macro_use] extern crate nickel;
use nickel::Nickel;
fn main() {
let mut server = Nickel::new();
server.utilize(router! {
get "**" => |_req, _res| {
"Hello world!"
}
});
server.listen("127.0.0.1:6767").unwrap();
}
</code></pre>
<h3>
<a name="designer-templates" class="anchor" href="#designer-templates"><span class="octicon octicon-link"></span></a>5. Run your app</h3>
<p>Congrats! You created your first nickel app. Just type <code>cargo run</code> on your console and visit <code>http://localhost:6767</code> in your browser. It should print out <code>hello world</code>.
</section>
</div>
</div>
</body>
</html>