29 lines
1.0 KiB
Markdown
29 lines
1.0 KiB
Markdown
# Getting Started
|
|
|
|
The easiest way to get started is to use the [starter](https://git.andrewlalis.com/Handy-Http/starter)
|
|
dependency, which automatically includes the components needed to boot up a
|
|
simple HTTP server.
|
|
|
|
In the example below, we create a new D project named **my-server**, and add
|
|
the `handy-http-starter` dependency to it.
|
|
```shell
|
|
dub init my-server
|
|
cd my-server
|
|
dub add handy-http-starter
|
|
```
|
|
|
|
Then, edit your main D function like so:
|
|
```d title="main.d"
|
|
import handy_http_starter;
|
|
|
|
void main() {
|
|
startServer((ref request, ref response) {
|
|
response.headers.add("Content-Type", "text/plain");
|
|
response.headers.add("Content-Length", "12");
|
|
response.outputStream.write(cast(ubyte[]) "Hello world!")
|
|
});
|
|
}
|
|
```
|
|
|
|
In the above code, we take advantage of Handy-Http Starter's shortcuts to quickly boot up an HTTP server on `http://localhost:8080` that responds to any request with `Hello world!`, by executing the provided [delegate function](https://tour.dlang.org/tour/en/basics/delegates) whenever a request is received.
|