From 99eef1d617ee2a19e594f55cd7d4a923115dde4d Mon Sep 17 00:00:00 2001 From: andrewlalis Date: Tue, 31 Mar 2026 20:34:09 -0400 Subject: [PATCH] Added initial mkdocs files. --- .gitignore | 5 +++++ README.md | 13 +++++++++++++ docs/getting-started.md | 28 ++++++++++++++++++++++++++++ docs/index.md | 7 +++++++ mkdocs.yml | 39 +++++++++++++++++++++++++++++++++++++++ 5 files changed, 92 insertions(+) create mode 100644 .gitignore create mode 100644 docs/getting-started.md create mode 100644 docs/index.md create mode 100644 mkdocs.yml diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f2a0659 --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +# Ignore Python virtual environment. +.env/ +# Ignore mkdocs build dir. +site/ +.cache/ \ No newline at end of file diff --git a/README.md b/README.md index 8ef1917..586dd3f 100644 --- a/README.md +++ b/README.md @@ -2,3 +2,16 @@ This repository contains the source code for the Handy-Http website that is used to showcase the project and provide easy access to documentation. + +The website is built using MkDocs, and we develop it in a Python [virtual +environment](https://docs.python.org/3/library/venv.html). + +## Setup +```shell +python3 -m venv .env +source .env/bin/activate +pip install mkdocs +pip install mkdocs-material +``` + +To exit the Python virtual environment, type `deactivate` in your shell. diff --git a/docs/getting-started.md b/docs/getting-started.md new file mode 100644 index 0000000..5fc5c49 --- /dev/null +++ b/docs/getting-started.md @@ -0,0 +1,28 @@ +# 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. diff --git a/docs/index.md b/docs/index.md new file mode 100644 index 0000000..04748e3 --- /dev/null +++ b/docs/index.md @@ -0,0 +1,7 @@ +# Home + +Welcome to the documentation site for Handy-Http. Here you'll find guides on how to get started with writing D web servers using Handy-Http, as well as detailed reference documentation for each of the various components that make up the project. + +## About Handy-Http + +Handy-Http is a collection of [D lang](https://dlang.org/) source libraries that provide a means for you to run an HTTP server. It started originally as an all-in-one hobby project that Andrew created a few years ago to escape from the clutches of Java's Spring ecosystem. D offers arguably better developer ergonomics, as well as monumental performance improvements due to its static compilation to machine code. Since its inception, it's gone through a few iterations before settling on the modular architecture presented here. diff --git a/mkdocs.yml b/mkdocs.yml new file mode 100644 index 0000000..658a09b --- /dev/null +++ b/mkdocs.yml @@ -0,0 +1,39 @@ +site_name: Handy-Http +site_url: https://handy-http.andrewlalis.com + +nav: + - Home: index.md + - Getting Started: getting-started.md + +theme: + name: material + palette: + # Palette toggle for automatic mode + - media: "(prefers-color-scheme)" + toggle: + icon: material/brightness-auto + name: Switch to light mode + # Palette toggle for light mode + - media: "(prefers-color-scheme: light)" + scheme: default + toggle: + icon: material/brightness-7 + name: Switch to dark mode + # Palette toggle for dark mode + - media: "(prefers-color-scheme: dark)" + scheme: slate + toggle: + icon: material/brightness-4 + name: Switch to system preference + +markdown_extensions: + - pymdownx.highlight: + anchor_linenums: true + line_spans: __span + pygments_lang_class: true + - pymdownx.inlinehilite + - pymdownx.snippets + - pymdownx.superfences + +plugins: + - privacy