Loco apps documentation - Matthjass13/RustForTheWeb GitHub Wiki

How to use the CRUD app

Preparations

Either do this :

  • Install Rust and Cargo : https://rust-lang.org/tools/install/

  • Clone this repository if not already done

  • Go to the Loco/locoapp folder and open terminal B (for backend)

  • Go to the Loco/locoapp/frontend folder and open terminal F (for frontend)

  • Run those commands :

  • cargo install loco (terminal B)
  • cargo install sea-orm-cli (terminal B)
  • npm install (terminal F)
  • npm run build (terminal F)
  • cargo loco start (terminal B) (launch the backend)
  • npm run dev (terminal F) (launch the frontend)
  • If you want to seed the db with some data :
  • Make sure you have no article yet
  • Open a new terminal in Loco/locoapp
  • Run this command : cargo loco db seed

Or just install docker desktop and launch the command "docker compose up --build" at the root of the project. The full application has been dockerised.

Usage

  • Access the app with http://localhost:3000/
  • You can see, the articles
  • You can add, edit, delete articles if you are connected
  • To create an account, launch this kind of command in bash while the backend is running (fill in the fields with what you want) : curl -X POST http://localhost:5150/api/auth/register
    -H "Content-Type: application/json"
    -d '{ "name": "", "email": "", "password": "" }'

Try the example of concurrency

Click on the analysis button to see how well a set of actions are performed on the articles either in sequence, or in parallel.

How to use the chat room / socket example

Note : this application has not been dockerised.

  • Go to the Loco/locosocket folder and open terminal
  • Launch the command cargo loco start
  • Access the app with http://localhost:5150/
  • Try accessing the app in multiple tabs and see what happens in one tab when you edit another one.
  • Source project : https://github.com/loco-rs/chat-rooms

What does it show ?

With only a few installs and command lines to generate models and controllers, it is relatively easy to build a CRUD application. We can then choose a framework to build the frontend on top of the backend.

We also see that when the operation cost a lot, it is more efficient to use concurrency to do them.