oliyh / pedestal-api

Easily build APIs in Pedestal using Schema and Swagger
MIT License
110 stars 13 forks source link

Table routing syntax #7

Closed Malabarba closed 8 years ago

Malabarba commented 8 years ago

Hi there. First of all, thank you for this project.

I looked through the readme and docstrings, but couldn't find an answer for this. Does pedestal-api's defroutes support the table routing syntax seen here?

(def application-routes
  (table/route-table
    {:host "example.com" :scheme :https}
    [["/user"          :get user-search-form]
     ["/user/:user-id" :get view-user        :constraints {:user-id #"[0-9]+"}]
     ,,,
     ]))

If not, would you know an alternative way to "swagger" such routes?

oliyh commented 8 years ago

Hi @Malabarba, glad you find it useful!

It looks like the table routing change is in the latest master but isn't released yet - I presume it will be in 0.4.2.

The current implementation of defroutes works from the terse pedestal routing syntax, and I see that is still supported in upcoming versions of pedestal. The table routing implementation may be able to emit the terse syntax - I haven't looked into it yet - in which case it could be supported with a small change in pedestal-api, but otherwise this would have to be supported in route-swagger.

@frankiesardo is this something you plan to look at?

Malabarba commented 8 years ago

FWIW, I believe I've got it to work by adding swagger doc to the interceptors, and then calling with-swagger on the return value of route-table.

frankiesardo commented 8 years ago

From what I see the table syntax expands to the same data structure the terse syntax expands to, so route-swagger.doc/with-swagger should still work and can already be used like

(def app-routes
 (->
   (table/route-table
     {}
     [["/user"                   :get  user-search-form]
      ...
      ["/user/:user-id/profile"  :put  update-profile]])
   (with-swagger {..}))

@oliyh you can have either have a separate entry point for the table expansion or just point out it still possible to use route-swagger directly if someone needs to.

frankiesardo commented 8 years ago

@Malabarba well done, glad to hear it's working

oliyh commented 8 years ago

@frankiesardo good that they both expand the same way, I will add a helper for table routes when pedestal 0.4.2 is released.

Good point about route-swagger still being available underneath, I'll make that clearer in the documentation, but it looks like @Malabarba already worked it out anyway!

ohpauleez commented 8 years ago

Pedestal will accept any routing format supported by the Routing Definition API. defroutes at this point is just a shorthand for syntax-quote. You shouldn't have to do anything special on your end, but if you need anymore information, feel free to reach out!