Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
    Malcolm Sparks
    @malcolmsparks
    Hi - new gitter channel to chat about bidi
    Ethan Miller
    @ezmiller

    Hello, I'm struggling a bit trying to get bidi to match a specific request. The example the docs give is oddly complex for a base example:

    ["/" {"blog" {:get {"/index" (fn [req] {:status 200 :body "Index"})}}}]

    I'm trying to do something a bit simpler. The equivalent of what in ExpressJS would be app.get('/notes/). Based on the above syntax it seems like this should be something like:

    ["/" {"notes" {:get some-handler-fn}]

    but this doesn't work. Can anyone here help?

    Ethan Miller
    @ezmiller

    Okay, I got it to work with this:

    (def routes
      ["/"
       [["home" home]
        ["api/" {"notes" {"" {:get get-notes}}}]
        [true not-found]]])

    I don't quite understand the logic of the syntax: for instance the first part ["/" ["home" home]], this seems to concatenate the index root / with home. But then when I want to add another level, i.e. /api/notes, I don't embed another vector, but rather a map: ["api/" {"notes" ...}]. Then, also it's not clear why it's necessary to include an empty string within the map that holds the different request handlers.

    sova
    @sova
    @ezmiller i can't speak authoritatively since I'm pretty new to bidi, but coming from compojureland I think it's good to look at it as a case statement. For instance, when we match "/" from the code you posted, then our next question is ... what's the next string. if it's /home we render our :home route.. if it's /api/ then we dig deeper and see if there's anything else to match...
    Kris Leech
    @krisleech
    Can anyone help with an example of RESTful routes with Bidi, this is what I have but I get a Duplicate key: ["/" :id] error:
    (def routes ["/" {"" index-handler
                            "admin" {""         admin-index-handler
                                     "/changes" { "" admin-changes-index-handler
                                                  "/new" admin-changes-new-handler
                                                  ["/" :id] { :post admin-changes-create-handler}
                                                  ["/" :id "/edit"] admin-changes-edit-handler
                                                  ["/" :id] { :put admin-changes-update-handler}
                                                  ["/" :id "/delete"] admin-changes-delete-handler}}}])
    Sameer Rahmani
    @lxsameer
    Hi , 1) is there any helper function to merge to routes with each other ? 2) what's the best way to add a route to a set of routes dynamically ? ( for example I want to add "/something" to a set of routes passed to a function )