Define routes in middleware

31 views
Skip to first unread message

Yang Yang

unread,
Feb 2, 2017, 6:01:33 PM2/2/17
to Ring
Hi all,
I am currently adding a mock data middleware into my application.

My idea is using middleware as a mock server, and integrate with the production code. When an endpoint is not implemented in the app, it returns a mock data from middleware layer.

e.g

saying there's a server 

(
-> 
app
middleware
)


request a (GET: /not-in-app)

goes into the server, and hit middleware route (:/not-in-app) and return.


request a (GET: /in-app)

goes into the app, and hit middleware route somehow aware the app already handled the request and transparently pass the result to client.

I wonder is that possible, or in this scenario is middleware the best choice?


Thanks.

James Reeves

unread,
Feb 2, 2017, 6:52:44 PM2/2/17
to Ring
Why not use a catch-all route? Routes in Compojure (which I guess you're using?) are matched in order, so if you add a route after all of your others, that will be triggered only if all the other routes don't match.

- James

--
You received this message because you are subscribed to the Google Groups "Ring" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ring-clojure+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages