Open Wulf opened 2 years ago
Outline for #11
@Wulf I would like to work on this task.
I have started by adding Axum
to the enum BackendFramework
and a main.rs+axum file. But, how do I go about testing just the server backend? Also, how is main.rs generated?
I would like to add features for the new backend step by step as I learn more about the axum framework and its workings.
hey @vishalsodani, hope things are well. Sorry for being super late with my reply.
It would be awesome if you added Axum! Step by step is exactly how I integrated poem-web
-- my focus was on getting the "Todo" example working.
Some things you should know in general:
+something
at the end is backend-specific and is not included in the final project if its backend isn't selected. In other words, create-rust-app_cli/template/backend/main.rs+active_web
would be copied into a generated project if the user selected active-web as their framework. (the main.rs+poem
one would be ignored).create-rust-app
crate which exposes features like backend-actix_web
and backend-poem
. When these features are enabled, it exposes plugin features for those backends (i.e. having the backend-actix_web
flag turned on should expose an auth plugin implementation for actix-web). You're more than welcome to put utility stuff for axum in the create-rust-app
crate. For example, I've got some 404 not found handlers in there for both actix-web and poem with the idea being that one day we will have a 404 page that is the same across all backends (at least in development).Apart from that, I went over the codebase once again and found places where you may want to add in Axum-related implementation / CLI options / etc. I've split the notes based on the project it pertains to:
create-rust-app_cli/src/main.rs
,
BackendFraemwork::Axum
around line 80create-rust-app_cli/src/content/project
+axum
file selection logic for the remove_non_framework_files
function -- I need to generalize this function eventually lolcreate-rust-app_cli/template/backend/
, add a main.rs+axum
file -- this will be the main.rs for the generated project :)create-rust-app_cli/template/backend/services
, copy and paste one of the todo.rs+...
files and rename it to todo.rs+axum
create-rust-app/Cargo.toml
, just add backend_axum = []
as a feature at the bottom of the file (you don't need to do anything else, as long as users can specify axum as a backend -- this is because the CLI adds this feature flag in the generated project's Cargo.toml for the create-rust-app
dependency -- it's what we did in point 1 above)I tried to over-explain everything to make it clear so sorry if it was too wordy.
After all this you'll hopefully have a working axum project which you can tweak further.
cd repo/create-rust-app_cli
cargo run -- test-project
# don't select any plugins~
Just a note, don't generate a project named 'test' -- it's not a legal cargo project name apparently -- I've run into this so many times now haha. If you choose to use another name for your generated test project (that isn't "test-project"), you should add it to the exclude array in repo/Cargo.toml
(otherwise cargo will complain and say it's part of a workspace or something like that). If all of this fails, just install the project:
cargo install --path repo/create-rust-app_cli
cd /somewhere/else
create-rust-app my-project
# don't select any plugins~
Let me know if I can help in any other way!
@wulf Thanks for sharing so many pointers :) This remove_non_framework_files
helped me immediately.
Hi @vishalsodani. Could I ask we done intergrated Axum?
Hi @vishalsodani. Could I ask we done intergrated Axum?
Sorry, no.
Adding a backend framework
Base requirements for each framework:
BackendFramework
enummain.rs
which starts the server increate-rust-app_cli/template/src/
/api/todos
endpoints (seetodo.rs
below)#[cfg(not(debug_assertions))]
) serves files from./frontend/build
with theindex.html
as the defaulttodo.rs
which serves the CRUD endpoints for the example 'todo' service increate-rust-app_cli/template/src/services
GET /
: returns a JSON list of all TODO itemsGET /id
: return a single JSON TODO itemPOST /
: creates and returns a single JSON TODO itemPUT /:id
: updates and returns a single JSON TODO itemDELETE /:id
: deletes a single item, returns 200 status codeOptional requirements:
(we can get to these later)
/api/auth
routesfiles.rs
)