#rest #demos #greeter #cargo-zigbuild #drone-io

bin+lib rgreeter

A simple REST API to greeter a user by name. Typically used for quick demos and checks.

3 releases

0.1.2 Feb 20, 2023
0.1.1 Feb 19, 2023
0.1.0 Feb 19, 2023

#957 in HTTP server

Download history 15/week @ 2024-02-23 63/week @ 2024-03-01 8/week @ 2024-03-08 5/week @ 2024-03-15

76 downloads per month

Apache-2.0

21KB
192 lines

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.

Dependencies

~11–20MB
~250K SLoC