cornucopia-rs / cornucopia

Generate type-checked Rust from your PostgreSQL.
Other
890 stars 41 forks source link

Add example with actix-web #201

Open farazfazli opened 1 year ago

farazfazli commented 1 year ago

Hi Louis,

I've been using your project and would like to add an example to the repo of using actix-web with Cornucopia. I feel this example would provide a starting point for users who want to use this project with a web server.

Looking forward to hearing your thoughts on this idea. Thanks.

farazfazli commented 1 year ago

@LouisGariepy What are your thoughts on this?

LouisGariepy commented 1 year ago

Hi @farazfazli, thanks for reaching out.

I would definitely be open to add more examples. There are some points I'd like to discuss before moving forward though.

First, I'd like to know what's the scope of the example you're thinking of. The most minimalist setup? A "todo" or "hacker news" example to show what's possible with Cornucopia?

Second, is there something that Cornucopia does that makes it's usage with webservers particularly difficult/obscure, or is the goal simply to provide a starting template? If it's the latter, then perhaps we should consider providing template repositories instead of examples. That way, users can leverage tools like cargo-generate (or simply download the repo, etc.), to get going quickly.

Finally, there are many popular webserver projects for Rust: axum, actix-web, warp, rocket, etc. I wouldn't want to give our users the impression that Cornucopia is somehow tied to a particular webserver. But at the same time, maintaining up-to-date implementations for many webservers might prove a maintenance burden.

I'd like to hear your thoughts on this :smile:

farazfazli commented 1 year ago

Hi @LouisGariepy,

Thanks for the detailed response! A todo list REST API example is a good idea. This can show how to have a configuration file for the database and also have a Dockerfile for quickly running a Postgres instance.

Really the idea is having a more complete API example which can easily be run on a developers machine. Yes it doesn't necessarily have to be actix-web as of course cornucopia is not tied to any particular webserver. I chose actix-web because it's the most popular one, and the API is stable.

Let me know your thoughts on this.

farazfazli commented 1 year ago

@LouisGariepy If you'd like, I can get started on this.

LouisGariepy commented 1 year ago

@farazfazli

I'm still debating if it's a good idea to include this example directly in the repo.

One reason is that to ensure that our examples are correct, we currently build and run the examples as part of the test suite. It's unclear to me how we could run a mock web server without bloating the example.

I'm also not sure about using a dockerfile with the "live" workflow, instead of the "managed" workflow used in other examples. My reasons are:

  1. Since the example must be runnable, we'd have to implement custom logic to handle spawning and removing this container in a safe way. This would duplicate much of the logic contained in the container module (which is crate-private).
  2. It's not clear to me what the custom dockerfile brings in this particular example. As far as I can tell it would be the same as any postgres dockerfile.

Basically I'd like to keep the examples in this repo well tested, directly related to Cornucopia, and as minimal as possible.


I see two paths forward with this issue:

  1. Find a way to make this example compatible with the concerns raised above.
  2. Create a supplementary repo where we can host examples that are "extra" (less minimal, showcasing more custom logic, with more dependencies, etc).

If we go with option 2, it could be a community project that we could shout-out in the README and the docs, or it could be included directly in the org. If we do include it in the org, we'd need to find someone dedicated to maintaining these examples.