#backend-server #config-toml #axum #config-file #mysql #orm #back-end

app prkserver

prkserver is a CLI tool that helps create a backend server in Rust using Axum and SQLx. It configures everything based on a provided config.toml file.

18 releases

new 0.2.8 Jan 6, 2025
0.2.7 Jan 6, 2025
0.1.9 Jun 18, 2024

#152 in Database interfaces

Download history 8/week @ 2024-09-18 4/week @ 2024-09-25 1/week @ 2024-12-04 7/week @ 2024-12-11 912/week @ 2025-01-01

920 downloads per month

MIT license

35KB
893 lines

prkserver

prkserver is a CLI tool that helps create a backend server in Rust using Axum and SQLx. It configures everything based on a provided config.toml file.

Features

  • Generates a Rust backend project using Axum for HTTP handling.
  • Configures SQLx for database interactions.
  • Supports PostgreSQL and MySQL databases.
  • Creates models, middlewares and endpoints as specified in the config.toml file.

Installation

To install prkserver, use cargo:

cargo install prkserver

Usage

To use prkserver, create a config.toml file that defines the project configuration. Here is an example config.toml file:

project_name = "backend_project"
database_url = "mysql://user:password@localhost/database_name"
database_type = "mysql" # postgres, mysql, sqlite

[[models]]
name = "User"
table_name = "users"
fields = [
    { name = "id", type = "i32" },
    { name = "username", type = "String" },
    { name = "email", type = "String" },
]
endpoints = [
    { method = "GET", path = "/users" },
    { method = "POST", path = "/users", body_params = [
        { name = "username", type = "String" },
        { name = "email", type = "String" },
    ] },
]


[[models]]
name = "Todo"
table_name = "todos"
fields = [
    { name = "id", type = "i32" },
    { name = "task", type = "String" },
    { name = "description", type = "Option<String>" },
]
endpoints = [
    { method = "GET", path = "/todos", middlewares = [
        "UserLoginHistoryMiddleware",
    ]  },
    { method = "POST", path = "/todos", middlewares = [
        "UserLoginHistoryMiddleware",
    ], body_params = [
        { name = "task", type = "String" },
        { name = "description", type = "Option<String>" },
    ]  },
    { method = "GET", path = "/todos/{id}", path_params = [
        { name = "id", type = "i32" },
    ] },
]

[[models]]
name = "UserLoginHistory"
table_name = "user_login_history"
fields = [
    { name = "user_id", type = "i32" },
    { name = "token", type = "String" },
]

[[middlewares]]
model = "UserLoginHistory"
select_from_model = "UserLoginHistory"
validate_header = [{ model_field = "token", header_key = "token" }]

Once you have your config.toml file, run prkserver at the path of this config file:

prkserver

This will generate a new project in a directory named after project_name specified in the config.toml.

Note: Still work in Progress.

Dependencies

~0.9–1.5MB
~30K SLoC