#ntex #framework #url #slash

ntex-remove-trailing-slash

Removing trailing slash on ntex Framework, inspired by actix's

1 unstable release

0.1.0 Jun 1, 2025

#25 in #ntex

MIT/Apache

9KB
54 lines

ntex-remove-trailing-slash

Removing trailing slash on ntex Framework

Usage

As in the description, this crate provides a middleware for the ntex framework that removes trailing slashes from incoming requests. So it will be possible to access the same resource with or without a trailing slash. This is useful for creating a consistent API where the presence or absence of a trailing slash does not affect the resource being accessed. So, GET /api/resource/ and GET /api/resource will both return the same resource. Inspired by actix's.

[dependencies]
ntex-remove-trailing-slash = { version = "0.1.0" }

Example

use ntex_remove_trailing_slash::RemoveTrailingSlash;
use ntex::{server::Server, web::{error::ErrorInternalServerError, route, scope, types::JsonConfig, App, HttpServer}};

pub fn create_new_www()->std::io::Result<Server>
{
    let app=HttpServer::new(|| {
        let ts=RemoveTrailingSlash::default();
        App::new()
        .wrap(ts)
    });
    app.bind(("0.0.0.0",80)?;
    Ok(app.run())
}

Dependencies

~13–28MB
~474K SLoC