rgreeter

Crates.iorgreeter
lib.rsrgreeter
version0.1.2
sourcesrc
created_at2023-02-19 05:50:19.712654
updated_at2023-02-20 10:23:20.973468
descriptionA simple REST API to greeter a user by name. Typically used for quick demos and checks.
homepage
repositoryhttps://github.com/kameshsampath/rust-greeter
max_upload_size
id788666
size68,965
Kamesh Sampath (kameshsampath)

documentation

README

Rust Greeter

A rust-lang demo on building API using axum.

The demo application will be crossed compiled into,

  • linux/arm64 (aarch64-unknown-linux-musl)
  • linux/amd64 (x86_64-unknown-linux-musl)

The demo uses cargo-zigbuild as tool for cross compilation.

Pre-requisites

Building Locally

cargo build

Start the server,

./target/debug/rgreeter

Testing

Open a new terminal Start the application to run integration tests,

PORT=8080 cargo run

On another terminal run,

cargo test

Testing Application

Once the server is up you can try the following REST URIs,

  • Default curl http://localhost:3000/ returns Hello World!
  • Greeting: curl http://localhost:3000/greet returns Hello! Anonymous!
  • Greeting a person: curl http://localhost:3000/greet?name=Jack returns Hello! Jack!

Build and Push Image to Docker Registry

Create a file .env under $PROJECT_HOME,

NOTE: You can copy the file .env.example to .env and update with your setting

PLUGIN_USERNAME=<container registry username>
PLUGIN_PASSWORD=<container registry password>
PLUGIN_REPO=<container image repo to push image>
PLUGIN_REGISTRY=<container registry to use>

e.g.

PLUGIN_USERNAME=octocat
PLUGIN_PASSWORD=octocat registry password
PLUGIN_REPO=ghcr.io/octocat/rgreeter
PLUGIN_REGISTRY=ghcr.io
task ci

Once the image is pushed run the following command,

docker-compose up 

Find the exposed port using the command docker ps and test the application the URIs.

NOTE: If the port 8080 is not available on your machine, try using other ports.

Commit count: 17

cargo fmt