To begin, clone the repository using SSH, then install all necessary dependencies by running:
cargo update
Create a config.yaml
file by duplicating the config.yaml.example
file provided in the repository. Add the services and parameters required for your application to run.
For development, run the following command to start the application:
cargo run --serve --conf <CONFIG_PATH> --specs <SPEC_PATH> --html <HTML_PATH>
This command will run the API Gateway in development mode. Ensure you specify the appropriate paths for your configuration file, OpenAPI spec, and HTML output.
For production builds, first build the release version of the application and then run it with the following commands:
cargo build --release
./target/release/hypergate --serve --conf <CONFIG_PATH> --specs <SPEC_PATH> --html <HTML_PATH>
This starts the API Gateway in production mode. Be sure to set up the correct paths for the configuration file, OpenAPI spec, and SwaggerUI HTML.
For automatic linting fixes, use:
rustfmt <FileName>
To run tests, use the following command:
cargo test
To add logs to your application, use the logger
object provided in the src/config/logger.rs
file. The logger is configured to write logs to the console and a file in the logs
directory. There are three log levels available:
info
warn
err
You can log messages by adding the following code to your methods:
logger.info("This is an info message", &[("key1", "val1"), ("key2", "val2")]);
logger.warn("This is an info message", &[("key1", "val1"), ("key2", "val2")]);
logger.err("This is an info message", &[("key1", "val1"), ("key2", "val2")]);
To run the application in a Docker container:
- Set the
config.yaml
to point to the deployed microservices.
Once these changes are made, ensure Docker is installed and running on your system, then build and start the container with:
docker compose up --build -d
This command launches your deployed Docker image in detached mode.
The Api-Gateway
includes two main commands: merge and serve.
This subcommand merges OpenAPI specifications into a single HTML output.
cargo run -- merge --specs <SPEC_DIR> --output <OUTPUT_PATH>
--url
: The URL of the API Gateway.--specs
: Directory of OpenAPI specs to merge.--output
: Output path of the merged HTML OpenAPI spec.
cargo run -- merge --specs "./docs/" --output "./static/openapi.yaml"
In this example, the command merges the OpenAPI specs located in the docs/
directory and generates a merged HTML spec at static/openapi.html
. The --url
argument specifies the API Gateway URL.
This subcommand serves the API Gateway, accepting the configuration file, OpenAPI spec, and SwaggerUI HTML path.
cargo run -- serve --conf <CONFIG_PATH> --specs <SPEC_PATH> --html <HTML_PATH>
--conf
: Path to the configuration file.--specs
: Path to the OpenAPI spec.--html
: Path to the SwaggerUI HTML.
cargo run -- serve --conf "config.yaml" --specs "./static/openapi.yaml" --html "./static/openapi.html"