onsi / gomega

Ginkgo's Preferred Matcher Library
http://onsi.github.io/gomega/
MIT License
2.13k stars 282 forks source link

With ghttp is there a way to setup a route handler to respond with sub handlers in order pr call #742

Open Jay-Madden opened 4 months ago

Jay-Madden commented 4 months ago

For example I have routes:

/foo/bar

and 

/baz/bax

I would like /foo/bar to respond to the first request to that url with {"data": 1} and the second request with {"data": 2}

I would like /baz/bax to respond to the first request to that url with {"data2": 3} and the second request with {"data2": 4}

I could not find a way to achieve this in the docs and am currently doing it via .AppendHandlers and putting all routes in there with verifies

onsi commented 4 months ago

hey @Jay-Madden - this isn’t directly supported. I’d probably approach this by using RouteToHandler and keeping track of the requests myself or by using AppendHandlers as you are.

if you see this pattern a lot you could implement a custom shim handler that takes an array of handlers and manages the ordering for you - then pass that handler on to RouteToHandler. I could share an example if that would be helpful.

Jay-Madden commented 4 months ago

Gotcha @onsi We can roll something up.

As a note, is there any interest in a feature addition/pr for soemthing like this assuming a workable design can be thought out?

onsi commented 3 months ago

hey sorry for the delay. if you come up with a pattern you like that’s also backward compatible i’d love to take a PR for this - thanks!