Giter Site home page Giter Site logo

rust-http-server-boilerplate's Introduction

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 :

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
  • Tide

All 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

  • No specific framework for HTTP and routing : Hyper and Tokio only.
  • Json support, both for encoding and decoding.
  • Mysql support for SELECT / INSERT statements.
  • Getopts to retrieve commande line parameters.
  • Env_logger to log data with customized format.
  • Toml to retrieve extra information from config file.
  • Serves files from www directory, and specific 404 handler.
  • 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 :

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 :

[database]
username = "your_username"
password = "your_password"
host = "localhost"
database_name = "your_database_name"

Then execute it thanks to cargo :

cargo r

That's it.

I hope this little code will help you.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.