csalex
In our Phoenix API we have implemented a batch endpoint that executes multiple requests in a single network call. It uses Task.async_stream/3 and Phoenix.ConnTest.dispatch/5 to execute each eachrequest asynchronously and return a unified response once all requests are executed.
So far it works as expected, although we use a test related functionality (dispatch/5 is defined in Phoenix.ConnTest).
I came across an issue when an endpoint expects both query and body params. dispatch/5 expects both body and query params to be passed on body_or_params (the 5th argument of the function) and automatically converts them to query or body params based on the HTTP request method. It seems like a distinction between body and query params is not possible, judging from the source code.
I tried to explicitly set those fields on the %Plug.Conn{} struct before dispatching but again, looking at the dispatch/5 source code, the connection is recycled, essentially keeping only some cookies and relevant headers, bringing me back to the use of body_or_params parameter.
The above raise my following questions:
- Is there a way to differentiate body and query params using the existing functionality?
- On a higher level, using a test related function to achieve this batching feature does not feel as the best approach, is there any alternative to that?
Trending in Questions
Other Trending Topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixirconf-us
- #blog-post
- #ai
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #hex
- #security
- #metaprogramming











Showing Posts 1 to 2- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
krasenyp
You might want to look into using
YourRouter.call/2instead ofPhoenix.ConnTest.dispatch/5. Using the latter in a non-test setup just feels strange to me.csalex
Thanks a lot, this solved the issue. This is also how
dispatch/5eventually executes the request