Skip to content

goreycn/api-in-rust

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

api-in-rust

api-in-rust is a rust http api server project.

Whom is this project for

Any developer who wants to develop api server in Rust language.

Requirements

currently use rust version 1.42.0

Installing

If you want to use BeanCheck util:

[dependencies]
bean_check = { path = "bean_check"}
bean_check_lib = { path = "bean_check_lib"}
regex = "1"

and white code in your main.rs

extern crate bean_check;
extern crate bean_check_lib;
extern crate regex;

use regex::Regex;
use bean_check::BeanCheck;
use bean_check_lib::BeanCheck;
use bean_check_lib::CheckError;
use std::str::FromStr;

#[derive(BeanCheck)]
struct UserDO {
    #[Min(30)]
    pub min_age: u32,
    #[Max(20)]
    #[Range(1, 100)]
    pub age: u16,
    #[Length(1, 13)]
    pub username: String,
    #[Pattern(r"^\d{1,5}$")]
    pub password: String,
    #[Email]
    pub email: String,
    pub mobile: String,
}

fn main() {
    let u = UserDO {
        min_age: 325,
        age: 20,
        username: "gorey".to_string(),
        password: "12345".to_string(),
        email: "aa@qq.com".to_string(),
        mobile: "13812341234".to_string()
    };

    match u.validate() {
        Ok(_) => { println!("check pass "); },
        Err(e) => { println!("{}", e); },
    }
}

About Debug Macro

You can install cargo-expand util, to see the pre-compiled code for macros witn command: cargo expand.

cargo install cargo-expand
# run command on main project where Cargo.toml located
cargo expand

Todo

  • Bean Check Macro
  • Param Bean Sign check
  • Log
  • MySQL handle
  • Redis handle

License

Licensed under either of Apache License, Version 2.0 or MIT license at your option.

About

a http api project in Rust lang.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages