vania-dart / framework

Fast, simple, and powerful backend framework for Dart built with ❤️
https://vdart.dev
MIT License
155 stars 12 forks source link

[Feature Request] - Resource and Any route #80

Closed javad-zobeidi closed 1 month ago

javad-zobeidi commented 1 month ago

Is your feature request related to a problem? Please describe. The current Router class lacks built-in support for defining routes that can handle any HTTP method any and for creating standard RESTful resource routes resource This makes it cumbersome to manage routes efficiently, requiring repetitive code and manual setup for each HTTP method and resource route.

Describe the solution you'd like I would like the Router class to include the following methods:

  1. Router.any: A method to define routes that respond to any HTTP method, allowing for flexible and DRY (Don't Repeat Yourself) route definitions.
  2. Router.resource: A method to create standard RESTful resource routes (index, create, store, show, edit, update, destroy) with built-in support for parameter validation.

Describe alternatives you've considered Manually Defining Routes: Manually defining each route for resource controllers and any method handlers, which leads to repetitive code and a higher risk of errors.

Additional context

// Example of using any method to handle any HTTP method
Router.any('req/any', (Request request) {
  return Response.json(request.all());
});

// Example of defining resource routes with validation
Router.resource('posts', PostController())
    .prefix('admin')
    .middleware([AuthMiddleware()]);