Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use parent path and controller in child nodes (routes.conf) #137

Closed
al3rez opened this issue Oct 19, 2017 · 5 comments
Closed

Use parent path and controller in child nodes (routes.conf) #137

al3rez opened this issue Oct 19, 2017 · 5 comments
Assignees
Labels
Projects

Comments

@al3rez
Copy link

al3rez commented Oct 19, 2017

Hey, I was looking through your framework and I really liked it. Is it possible to do this? or any other better ways to remove duplication.

Expected:

domains {
  localhost {
    name = "new routes"
    host = "localhost"
    redirect_trailing_slash = true
    method_not_allowed = true
    auto_options = true
    routes {
      baskets {
        path = "/baskets"
        controller = "BasketController"
        auth = "anonymous"
        index {
          action = "Index"
        }
        create {
          action = "Create"
        }
      }
    }
  }
}

Can Do: (It works now but not DRY)

domains {
  localhost {
    name = "new routes"
    host = "localhost"
    redirect_trailing_slash = true
    method_not_allowed = true
    auto_options = true
    routes {
      baskets {
        path = "/baskets"
        routes {
          show_basket {
            path = "/"
            controller = "BasketController"
            action = "Index"
            auth = "anonymous"
          }
          create_basket {
            path = "/"
            method = "POST"
            controller = "BasketController"
            action = "Create"
          }
        }
      }
    }
  }
}

Actual:

domains {
  localhost {
    name = "new routes"
    host = "localhost"
    redirect_trailing_slash = true
    method_not_allowed = true
    auto_options = true
    routes {
      v1 {
        path = "/v1/"
        routes {
          baskets {
            path = "/baskets"
            controller = "BasketController"
            action = "Index"
            auth = "anonymous"
          }
          create_basket {
            path = "/baskets"
            method = "POST"
            controller = "BasketController"
            action = "Create"
          }
        }
      }
    }
  }
}

@jeevatkm
Copy link
Member

@azbshiri I'm glad to hear, you liked aah framework.

Nested routes config works like this:

routes {
  <route_name1> {
    # this route attributes

    # child routes - level 1
    routes {
      <route_name11> {
        # this route attributes

        # child routes - level 2
        routes {
          <route_name111> {

            # you can go on any level with your creativity
            
          }        
        }
      }
    }
  }

  <route_name2> {
    # same as above
  }
}
  • path - inherits the parent path as prefix to child path
  • method - have to be provided otherwise GET is chosen
  • controller - have to be provided for every routes
  • action - if not provided then value is chosen based on HTTP method value
  • auth - value is inherited from parent as-is if not provided in the child route
  • max_body_size - if not provided then request.max_body_size config value from aah.conf
  • anti_csrf_check - default is true for web application, for REST API this doesn't take effect even if its defined

While composing this answer, I thought below enhancement:

  • inherit controller value if not provided in the child route (will add this enhancement in the v0.10 release)

Feel free suggest and recommend improvements to routes config and any area in the aah.

@jeevatkm jeevatkm self-assigned this Oct 19, 2017
@jeevatkm
Copy link
Member

@azbshiri I have described above, how its currently processing the routes.conf.

Can you propose the improve the improvements onroutes.conf? Routes processing code is here.

I'm looking forward to your inputs and contributions.

@jeevatkm
Copy link
Member

jeevatkm commented Oct 19, 2017

Also I will add following enhancement too. route name is plays key role, it must be provide.

  • path - if its not provided in child route inherit parent use as-is.

With v0.10 release onwards you can do:

Your second example will turn into:

routes {
  baskets {
    path = "/baskets"
    controller = "BasketController"
    routes {
      show_basket {
        action = "Index" # it can be ignored, since default HTTP method value is `GET` and for that action name is `Index`
        auth = "anonymous"
      }
      create_basket {
        method = "POST"
        action = "Create" # it can be ignored, since action name `Create` is mapped to POST
      }
    }
  }
}

@jeevatkm jeevatkm added enhancement lib-router Request Routing and removed support labels Oct 20, 2017
@jeevatkm jeevatkm added this to the v0.10 Milestone milestone Oct 20, 2017
jeevatkm added a commit to go-aah/router that referenced this issue Oct 20, 2017
* path - if its not provided in child route inherit parent use as-is.
* controller - if its not provided in the child route inherit parent use as-is.
@jeevatkm
Copy link
Member

@azbshiri I have just added these two enhancements. Its available on aah edge version, you can give it try and share your feedback.

  • path - if its not provided in child route inherit parent use as-is.
  • controller - if its not provided in the child route inherit parent use as-is.

Once you installed aah version v0.9 then you can execute aah switch command to try out v0.10edge version.

Now routes config become (your second example from the question):

routes {
  baskets {
    path = "/baskets"
    controller = "BasketController"
    routes {
      show_basket {
        auth = "anonymous"
      }
      create_basket {
        method = "POST"
      }
    }
  }
}

@jeevatkm jeevatkm added this to v0.10 - In Progress in aah Roadmap Oct 20, 2017
@al3rez
Copy link
Author

al3rez commented Oct 20, 2017

Thanks for your attention and fast response. I'll check that and let you know.

@jeevatkm jeevatkm moved this from v0.10 - In Progress to v0.10 - Completed in aah Roadmap Feb 24, 2018
@jeevatkm jeevatkm moved this from v0.10 - Completed to Released to Audience in aah Roadmap Mar 29, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
aah Roadmap
  
Released to Audience
Development

No branches or pull requests

2 participants