Can I get the response of a reverse proxy request in a template?

1. Caddy version (caddy version): v2.4.6

2. How I run Caddy:

This is all local development for testing Caddy.

a. System environment:

MacOS Big Sur

b. Command:

caddy run

c. Service/unit/compose file:

Paste full file contents here.
Make sure backticks stay on their own lines,
and the post looks nice in the preview pane.

d. My complete Caddyfile or JSON config:


reverse_proxy {
              handle_response {
                              try_files posts.html

3. The problem I’m having:

I have a test JSON API running on port 3000, and I am reverse proxying on port 9000. That all works fine. What I would like to do is get the response from the JSON API and use the response in a template.

So, if the API responds with:

    "id": 1,
    "title": "Post 1"

I would like to be able to use that value in the template. But, don’t see any reference to a response object available for templates.

4. Error messages and/or full log output:

Nothing to output because I am still trying to figure out how to get the response into the template.

5. What I already tried:

I have tried to search the internet for someone trying to do something similar, but I just can’t seem to find what I am trying to do. Or, maybe I am not understanding properly how to do what I am trying to do in Caddy.

Not currently, but that’s a good idea. Looks useful.

Want to open an issue on GitHub to request this?

1 Like

Yes, submitted it here. Let me know if/how I can help.

1 Like

This topic was automatically closed after 30 days. New replies are no longer allowed.