I have been considering how a routing library like Roda might work in Crystal. One oddity of the library is that it uses
throw to return from a request handler block (here’s an example). If you aren’t familiar with Ruby’s throw/catch opposed to the normal raise/rescue, here’s a stackoverflow question that might be helpful: What is the difference between Raising Exceptions vs Throwing Exceptions in Ruby? - Stack Overflow
Does anyone know if there’s something roughly equivalent in Crystal?
The api is something like:
class MyApp < Roda route do |r| r.get("/users") do json User.all end # throw is called after these blocks are run # so the request doesn't run more code # than it needs to r.get("/users/:id") do |id| json User.find(id) end end end