0. Install Rust
0.1 Install Rustup
Rustup is a toolchain manager for Rust.
$ curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
$ source "$HOME/.cargo/env"
0.2 Install Rust
$ rustup default stable
0.3 Create a new project
$ cargo new hello_world
$ cd hello_world
$ cargo run
1. Hello World with Rocket
1.1 Rocket Hello World
$ git clone https://github.com/SergioBenitez/Rocket.git
$ cd Rocket/examples/hello
$ cargo run
2. OpenAPI generator in Rust
2.1 Install OpenAPI Generator
$ brew install openapi-generator
2.2 Generate Rust Server
2.2.1. Create a openapi.yaml
file in the root of your project.
-
If there is no
openapi.yaml
file, you can create it from scratch. -
Or you can generate it from a swagger url.
$ openapi-generator generate -i https://petstore.swagger.io/v2/swagger.json -g openapi-yaml -o .
- Or you can find a sample file in the
openapi-generator
repo.
2.2.2. Generate Rust Server
$ openapi-generator generate -i openapi.yaml -g rust-server
If you want to create a project into a specific folder, you can use the -o
option.
$ openapi-generator generate -i openapi.yaml -g rust-server -o ./my_project
2.2.3. Build and Run
$ cargo build
$ cargo run