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

Extracting parameters from request #51

Open
arnaudbriche opened this issue Jun 10, 2013 · 4 comments
Open

Extracting parameters from request #51

arnaudbriche opened this issue Jun 10, 2013 · 4 comments

Comments

@arnaudbriche
Copy link

Is it possible to extract parameters with the router to pass to a pipeline stage ?

@smw1218
Copy link
Contributor

smw1218 commented Jun 10, 2013

Yes. Since SelectPipeline(req *Request) (pipe RequestFilter) has access to the request, you can do any sort of parsing and saving of parameters in the Context on the request. You can see an example here:

https://github.com/ngmoco/pat/blob/master/falcore_mux.go#L23

@dgrijalva
Copy link
Contributor

If you want to do param parsing, but not routing, you can simply use a RequestFilter. Requests have a Context property you can use to store data you want to be accessible to later staging. For example, parsed query information or authentication state data.

@arnaudbriche
Copy link
Author

Thx, not sure I totallyget it.
Is it possible to use pat in conjonction with falcore to get both pipelines functionality and restful routing ?
Not sure it's clear enough; i'm currently using https://github.com/drone/routes to do the routing for my app; it looks as follows

router := routes.New()
router.Filter(Authenticate)
router.Get("/", RootHandler) 

campaignsController := new(campaigns.CampaignsController)

router.Get ("/campaigns", func(resp http.ResponseWriter, req *http.Request) { campaignsController.List(resp, req)   })
router.Post("/campaigns", func(resp http.ResponseWriter, req *http.Request) { campaignsController.Create(resp, req) })
router.Get ("/campaigns/:id", func(resp http.ResponseWriter, req *http.Request) { campaignsController.Read(resp, req)   })
router.Put ("/campaigns/:id", func(resp http.ResponseWriter, req *http.Request) { campaignsController.Update(resp, req) })
router.Del ("/campaigns/:id", func(resp http.ResponseWriter, req *http.Request) { campaignsController.Delete(resp, req) })

http.Handle("/", router)

But I'm missing the "after filter" functionality.
Is it possible to do the same with falcore while getting all the cool stuff it adds up ?

@smw1218
Copy link
Contributor

smw1218 commented Jun 13, 2013

The ngmoco/pat fork will do restful routes in the same way as your example from drones/routes.

The one thing that is a major difference is the signature for a falcore RequestFilter is quite different from the standard library. We wrap the http.Request in a falcore.Request and also return an http.Response rather than using the http.ResponseWriter. It shouldn't be difficult to convert your controllers to use the falcore signature instead.

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

3 participants