NgynHttpEngine

Trait NgynHttpEngine 

Source
pub trait NgynHttpEngine: NgynPlatform {
    // Provided methods
    fn route(
        &mut self,
        path: &str,
        method: Method,
        handler: impl Into<RouteHandler>,
    ) { ... }
    fn get(&mut self, path: &str, handler: impl Into<RouteHandler>) { ... }
    fn post(&mut self, path: &str, handler: impl Into<RouteHandler>) { ... }
    fn put(&mut self, path: &str, handler: impl Into<RouteHandler>) { ... }
    fn delete(&mut self, path: &str, handler: impl Into<RouteHandler>) { ... }
    fn patch(&mut self, path: &str, handler: impl Into<RouteHandler>) { ... }
    fn head(&mut self, path: &str, handler: impl Into<RouteHandler>) { ... }
    fn use_static(&mut self, path_buf: PathBuf) -> Result<()> { ... }
}

Provided Methods§

Source

fn route( &mut self, path: &str, method: Method, handler: impl Into<RouteHandler>, )

Adds a route to the application.

§Arguments
  • path - The path of the route.
  • method - The HTTP method of the route.
  • handler - The handler function for the route.
§Examples

struct MyEngine;

let mut engine = MyEngine::default();
engine.route('/', Method::GET, Box::new(|_, _| {}));
Source

fn get(&mut self, path: &str, handler: impl Into<RouteHandler>)

Adds a new route to the NgynApplication with the Method::Get.

Source

fn post(&mut self, path: &str, handler: impl Into<RouteHandler>)

Adds a new route to the NgynApplication with the Method::Post.

Source

fn put(&mut self, path: &str, handler: impl Into<RouteHandler>)

Adds a new route to the NgynApplication with the Method::Put.

Source

fn delete(&mut self, path: &str, handler: impl Into<RouteHandler>)

Adds a new route to the NgynApplication with the Method::Delete.

Source

fn patch(&mut self, path: &str, handler: impl Into<RouteHandler>)

Adds a new route to the NgynApplication with the Method::Patch.

Source

fn head(&mut self, path: &str, handler: impl Into<RouteHandler>)

Adds a new route to the NgynApplication with the Method::Head.

Source

fn use_static(&mut self, path_buf: PathBuf) -> Result<()>

Sets up static file routes.

This is great for apps tha would want to output files in a specific folder. For instance, a public directory can be set up and include all files in the directory

The behavior of use_static in ngyn is different from other frameworks.

  1. You can call it multiple times, each call registers a new set of routes
  2. The files in path_buf folder aren’t embedded into your binary and must be copied to the location of your binary
§Arguments
  • path_buf - static folder, relative to Cargo.toml in dev, and the binary in release

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§