Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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 this issue Mar 14, 2024 · 3 comments

Comments

@Jay-Madden
Copy link

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
Copy link
Owner

onsi commented Mar 15, 2024

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
Copy link
Author

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
Copy link
Owner

onsi commented Mar 21, 2024

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants