#file-server #local #hyper-http #http-file #static-file #asynchronous-programming

app basic-http-server

A simple static HTTP file server, for learning and local development

15 unstable releases (6 breaking)

0.8.1 Jan 2, 2020
0.8.0 Nov 16, 2019
0.7.1 Nov 16, 2019
0.6.3 Jul 30, 2019
0.1.0 Mar 2, 2016

#554 in HTTP server

Download history 25/week @ 2023-12-04 16/week @ 2023-12-11 38/week @ 2023-12-18 33/week @ 2023-12-25 35/week @ 2024-01-01 47/week @ 2024-01-08 33/week @ 2024-01-15 30/week @ 2024-01-22 40/week @ 2024-01-29 31/week @ 2024-02-05 41/week @ 2024-02-12 69/week @ 2024-02-19 61/week @ 2024-02-26 58/week @ 2024-03-04 62/week @ 2024-03-11 74/week @ 2024-03-18

261 downloads per month

MIT/Apache

32KB
597 lines

basic-http-server

A simple static HTTP server, for learning and local development.

basic-http-server is designed for two purposes:

  • as a teaching tool. It is a simple and well-commented example of basic tokio, hyper, and asynchronous Rust programming, with async / await.

  • for local development. It serves static HTML content, and with the -x flag, provides convenience features useful for creating developer documentation, including markdown rendering and directory listing.

The entire reference source for setting up a hyper HTTP server is contained in main.rs. The ext.rs file contains developer extensions.

Developer extensions

When passed the -x flag, basic-http-server enables additional conveniences useful for developing documentation locally. Those extensions are:

  • Rendering files with the ".md" extension as Markdown.

  • Listing directories when no "index.html" file is found.

  • Serving common source code files as "text/plain" so they are rendered in the browser.

This makes basic-http-server useful for the following scenarios:

  • Previewing markdown content. Draft your README.md changes and view them locally before pushing to GitHub.

  • Navigating to local documentation, including Rust API documentation. Just run basic-http-server -x in your project directory, and use the directory listing to navigate to target/doc, then find the crates to read from there (cargo doc doesn't put an index.html file in target/doc).

Installation and Use

Note that basic-http-server is not production-ready and should not be exposed to the internet. It is a learning and development tool.

Install with cargo install:

$ cargo install basic-http-server
$ basic-http-server

To turn on the developer extensions, pass -x:

$ basic-http-server -x

To increase logging verbosity use RUST_LOG:

RUST_LOG=basic_http_server=trace basic-http-server -x

Command line arguments:

USAGE:
        basic-http-server [FLAGS] [OPTIONS] [ARGS]

FLAGS:
    -x               Enable developer extensions
    -h, --help       Prints help information
    -V, --version    Prints version information

OPTIONS:
    -a, --addr <ADDR>    Sets the IP:PORT combination (default "127.0.0.1:4000")

ARGS:
    ROOT    Sets the root directory (default ".")

License

MIT/Apache-2.0

Dependencies

~22MB
~400K SLoC