1
0
mirror of https://github.com/actix/actix-website synced 2024-11-24 16:52:59 +01:00
actix-website/content/docs/getting-started.md
Sven-Hendrik Haase e3b3a7ebbe
Add heading to auto-reloading bit
This makes it a bit more visually distinguished from the paragraph before. I think that's a good thing as it's essentially a completely separate topic.
2019-08-05 17:29:01 +02:00

54 lines
1.7 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

---
title: Getting Started
menu: docs_basics
weight: 130
---
# Getting Started
Lets write our first `actix-web` application!
## Hello, world!
Start by creating a new binary-based Cargo project and changing into the new directory:
```bash
cargo new hello-world
cd hello-world
```
Now, add `actix-web` as dependencies of your project by ensuring your `Cargo.toml`
contains the following:
```ini
[dependencies]
actix-web = "{{< actix-version "actix-web" >}}"
```
In order to implement a web server, we first need to create a request handler.
A request handler is a function that accepts zero or more parameters that can be
extracted from a request (ie, `impl FromRequest`) and returns a type that can be
converted into an `HttpResponse` (ie, `impl Responder`):
{{< include-example example="getting-started" section="setup" >}}
Next, create an `App` instance and register the request handler with the application's
`route` on a *path* and with a particular *HTTP method*. After that, the application
instance can be used with `HttpServer` to listen for incoming connections. The server
accepts a function that should return an application factory.
{{< include-example example="getting-started" section="main" >}}
That's it! Now, compile and run the program with `cargo run`.
Head over to ``http://localhost:8088/`` to see the results.
### Auto-reloading
If you want, you can have an automatically reloading server during development
that recompiles on demand. This isn't necessary, but it makes rapid prototyping
more convenient as you can see changes instantly upon saving.
To see how this can be accomplished, have a look at the [autoreload pattern][autoload].
[autoload]: ../autoreload/