Can I used Caddy to run server with custom REST API?

1. Caddy version (2):

2. How I run Caddy:

Standard Caddy 2 setup.

a. System environment:

Ubuntu 18.04 or 20.04 Linux, or MacOS 10.9+

3. The problem I’m having:

I understand how Caddy can be used to have a flexible web server with static content.

How can I use Caddy to run a server with custom REST API writting in Go?

6. Links to relevant resources:

I cannot find ANY examples of Caddy being used to support a custom REST API. Is it even possible?

Yep, you can use Caddy as a library in Go (less common), or you can use the reverse_proxy directive if you want to run them separately (most common).

1 Like

Thanks! Two questions:

  1. How much overhead is there to going through a reverse proxy?
  2. Do you have any links to projects that use Caddy as a library in Go?

Caddy won’t be your bottleneck unless you get to very high amounts of requests per second. Don’t worry about premature optimization.

Sorry, I’m not aware of any that use Caddy v2 yet, @matt might know of some though. I figure this is an area where we’ll need some documentation though.

Alternatively, you could use CertMagic as a library if the main thing you need is automatic HTTPS. It’s the library that’s at the core of Caddy to provide this. There’s plenty of people using it (but unfortunately I can’t really offer any examples, I’m not following who uses it very closely).

1 Like

I’d go so far as to say ludicrous amounts. Just to back this point up a bit, Caddy is a Golang web server, and not only are these kinds of servers deployed by some seriously huge enterprises in service of major traffic, so far even just for Caddy 2 we’ve seen extremely optimistic benchmarks and extremely pessimistic ones, varying wildly based on what it’s being compared to (e.g. vs. highly specialized / optimized code, or vs. out-of-the-box standard nginx) and what hardware it’s run on.

Caddy v2 will serve you with distinction, right up to the point where you need to eke out every single shred of perf you can, and have the skills and tools required to identify bottlenecks in your servers. At that stage, you’ll already know what you need to do.


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