crates.io MIT licensed

AthenaEngine

Web server engine for rust

External library

[dependencies] chrono = "0.4.23" urlencoding = "2.1.2"

How to use?

```Rust use std::collections::HashMap; use AthenaEngine::server; use AthenaEngine::server::pagemanager::pagemanager; use AthenaEngine::server::pagemanager::pagemanager::PageInfo; use AthenaEngine::server::responseparser::responseparser::{defaultresponsewriter, IsResponseDataCreateSuccess, Response, ResponseCookies};

fn main() { // All pages hashmap let mut allpagelist: HashMap = HashMap::new(); // 'hello.html' page setting let hellopageinfo : PageInfo = PageInfo { filepath: "A:\AthenaEngine\Rust\hello.html".tostring(), // HTML file path isaccess: true // File accessibility }; // '/hello.html' -> connection name // Insert hello page allpagelist.insert(String::from("/hello.html"), hellopageinfo); // All pages list setting unsafe { pagemanager::ALLPAGES.pages = Some(allpage_list); }

// Client connection event setting
unsafe {
    // Request event setting
    server::EVENT.event_request = Some(Box::new(|request| {
        // Do
    }));
    // Response event setting
    server::EVENT.event_response = Some(Box::new(|request| {
        // Cookies setting
        let mut cookies_list : Vec<ResponseCookies> = Vec::new();
        let cookie : ResponseCookies = ResponseCookies {
            name: "test-my-cookie".to_string(),
            value: "test-my-cookie-value".to_string(),
            path: "/".to_string(),
        };
        cookies_list.push(cookie);
        // Default response packet
        let response : Response = default_response_writer(&request, Some(cookies_list), None);

        // Get response value
        if response.is_success == IsResponseDataCreateSuccess::SUCCESS {
            match &response.headers {
                None => {}
                Some(value) => {
                    // Print all headers
                    println!("{:?}", value);
                }
            }
        }

        // Return response
        return response;
    }));
}

// Open server
server::start_server(String::from("127.0.0.1"), 4444);

} ```

Expansion module description

server::pagemanager::pagetemplate_parser (function)

You can invoke body structure and template functions. You can also use an external template engine template engine without using this feature.

WARNING! This grammar is not perfect. The programmer may not behave as intended.

This grammar requires open (\r\n) characters and should not be indented (Tab) when using dedicated grammar.

< Grammar >

Variable notation: <#>var.(Variable name)

Recurring statement notation: <#>control.for (start num),(end num)

Repeating statement termination notation: <#>control.for_end

< Rust file > ```Rust // Response event setting server::EVENT.eventresponse = Some(Box::new(|request| { // Default response packet let mut response : Response = defaultresponse_writer(&request, None, None);

// Parse html match &response.body { None => {} Some(responsebody) => { match &responsebody.bodystr { None => {} Some(html) => { // Get default body // Add variable let mut var : HashMap = HashMap::new(); var.insert(String::from("variable1"), Box::new(|| { return String::from("Hello my var!"); })); // Parsing html let changebody : String = pagetemplateparser(html.clone(), var); // Apply original response body let responsebody : ResponseBody = ResponseBody { bodystr: Some(changebody), }; let mut newresponse : Response = Response { issuccess: response.issuccess, responsecode: response.responsecode, httpversion: response.httpversion, headers: response.headers, cookies: response.cookies, body: Some(responsebody), };

              return new_response;
          }
      }
  }

}

// Return response return response; })); ```

< HTML file > HTML <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> </head> <body> <#>var.variable_1 <#>control.for 0,10 print 1 -- 10 <#>control.for_end </body> </html>

log::logwriter, log::logmoretextwriter (function)

>

The dedicated Log Output Manager lets you print logs beautifully. ```Rust // Error log println!("{}", logtextwriter(error.tostring(), String::from("Log Generating entity"), LogTypeTag::WARNING)); println!("{}", logmoretextwriter(error.to_string(), String::from("Log Generating entity"), LogTypeTag::WARNING), String::from("More text"));

// [Output Results] // 2022/12/16 01-29-51 INFO [MAIN/SERVER] [IP:127.0.0.1] Run request EVENT handler. // 2022/12/16 01-38-17 INFO [MAIN/SERVER/RESPONSE_PARSER] Default response packet creation succeeded. ```

License

MIT License

Copyright (c) 2022 CHOI SI-HUN

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.