Is there a built-in way using ASP.NET Core to do standard nested routing in the same manner as in most other languages? How do I do in C# what I show below in Go and JS?
Example in Go using chi:
r := chi.NewRouter()
r.Use(amiddleware) // Use some middleware
r.Group(func(r chi.Router) { // A group with further configuration
r.Use(another) // Middleware that only applies to group
r.Route("/trunk", func(r chi.Router) { // First level of a nested route
r.Route("/branch", func(r chi.Router) { // Next level
r.Get("/leaf", Leaf) // An endpoint
})
})
})
func Leaf(w http.ResponseWriter, r *http.Request) { ... }
http.ListenAndServe(":8080", r) // Start it up
Example in JS using express:
const app = express()
app.use(amiddleware) // Use middleware
app.use(Router(). // A group with further configuration
use(another). // Middleware that only applies to group
use('/trunk', Router(). // First level of a nested route
use('/branch', Router(). // Next level
get('/leaf', leaf) // An endpoint
)
)
)
function leaf(req, res, next) { ... }
app.listen(8080) // Start it up