Hello community
I’ve recently released plug_loopback
, a library to programmatically call your own (Phoenix) endpoints:
You can form a new request from a Phoenix endpoint:
MyAppWeb.Endpoint
|> PlugLoopback.from_phoenix_endpoint()
|> PlugLoopback.get("/some/path", [{"some", "header"}])
|> Plug.Conn.put_req_header("another", "header")
|> PlugLoopback.run()
or replay any Plug.Conn{}
:
conn
|> PlugLoopback.replay()
|> PlugLoopback.run() # Here is a very good opportunity to create an infinite loop!
I needed it to implement the stale-while-revalidate
cache-control header in plug_http_cache
, but it can be useful for other uses-cases:
- warming up cache at startup by directly calling the pages you want to cache
- debugging in the shell
- and probably others
It’s very similar to Phoenix.ConnTest
but intends to be more production-ready (replays / auto-encodes the body, simple API) and possibly be Phoenix-independant in the future.
Any suggestion or contribution is welcome.
Cheers