Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/xigh/rust-http-server-boilerplate
A simple and stupid, but working Rust HTTP Server
https://github.com/xigh/rust-http-server-boilerplate
boilerplaite hyper mysql rust tokio uptodate
Last synced: about 2 months ago
JSON representation
A simple and stupid, but working Rust HTTP Server
- Host: GitHub
- URL: https://github.com/xigh/rust-http-server-boilerplate
- Owner: xigh
- License: mit
- Created: 2023-03-28T19:56:04.000Z (almost 2 years ago)
- Default Branch: master
- Last Pushed: 2024-03-23T18:24:55.000Z (10 months ago)
- Last Synced: 2024-03-23T19:29:14.886Z (10 months ago)
- Topics: boilerplaite, hyper, mysql, rust, tokio, uptodate
- Language: Rust
- Homepage:
- Size: 83 KB
- Stars: 4
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Rust http server boilerplate
**Without any specific http framework**
This is a simple code, written in Rust programming language.
## New version (0.2.0)
Updated crates to :
```toml
hyper = { version = "1.2.0", features = ["full"] }
hyper-util = { version = "0.1", features = ["full"] }
tokio = { version = "1.27.0", features = ["full"] }
```## Disclaimer (was for 0.1.0)
I started to write it for my needs, and at the same time, I wanted to know how helpful it would be to develop with the help of ChatGPT4.
Please note that I did not asked ChatGPT4 to write the whole code, it is too complex to do that. I only asked how to use the crates I wanted to use.
I'll write a blog article on this as soon as possible.## Why ?
The main idea with this program is to be up to date with the **latest version of all imported crates** (as of March, the 29th, 2023).
I also wanted to write something light and as simple stupid as possible ! Thus there is no high level crates such as :
* Rocket
* Actix-web
* Warp
* TideAll theses crates are *mindblowing* and I **strongly** recommand to use them. But this code is both for learning purpose and the felling of having fine grained control on the functionnalities.
## Specs
* [x] No specific framework for HTTP and routing : **Hyper** and **Tokio** only.
* [x] **Json** support, both for encoding and decoding.
* [x] **Mysql** support for SELECT / INSERT statements.
* [x] Getopts to retrieve commande line parameters.
* [x] Env_logger to log data with customized format.
* [x] Toml to retrieve extra information from config file.
* [x] Serves files from www directory, and specific 404 handler.
* [x] All put in different modules. This might not be as clean as a whistle, but enough to understand how to proceed.## Todos
* [ ] Upload files
* [ ] unzip files
* [ ] image check and resize
* [ ] qrcode
* [ ] MySQL SSL (for Azure)
* [ ] GraphQL support
* [ ] JWT - Json Web Token
* [ ] Password encryption
* [ ] Rate limiting and bandwidth control
* [ ] Ssl support
* [ ] Ability to send emails from templates
* [ ] Write a simple documentation explaining how all this works
* [ ] MongoDB support
* [ ] PostgreSQL support
* [ ] OpenAPI / Swagger support
* [ ] Request to another HTTP Server / REST / GraphQL
* [ ] Protocol Buffer
* [ ] Websockets
* [ ] **name yours ...**## How to use it
It requires a database. You must first prepare a `users` table with this :
```mysql
CREATE TABLE users (
id INT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(255),
email VARCHAR(255) UNIQUE
);
```And then copy the file `config.toml.example` to `config.toml`, editing your database parameters :
```toml
[database]
username = "your_username"
password = "your_password"
host = "localhost"
database_name = "your_database_name"
```Then execute it thanks to cargo :
```bash
cargo r
```That's it.
I hope this little code will help you.