Pluto is a RESTful app that can accept "currency" values uploaded by the user. Such values are then converted and stored into a Postgres table.
Pluto uses a number of open source projects to work properly:
- Rust - A language empowering everyone to build reliable and efficient software
- Postgres - The World's Most Advanced Open Source Relational Database
- Hasura - Blazing fast, instant realtime GraphQL APIs on your DB
- Rweb - Yet another web server framework for rust
- SQLx - The Rust SQL Toolkit
And of course Pluto itself is open source with a public repository on GitHub.
- After executing the RESTful server a route capable to perform the currency conversion will be exposed at
<basePath>/exchanges
by issuing aPOST
request. - The payload must contain the following keys:
currencyFrom
,currencyTo
,amountFrom
,createdAt
. - For basic usage and examples please refer to the following sections: Docker, Curl examples.
Pluto requires Rust v1.56+ toolchain, Hasura v2+, and Postgres v14+ to run.
Install the Rust runtime following respective documentation. Then move on repo folder and provide a custom .env
file, ie:
cp .env.example .env
Now in order to compile/execute the RESTful server, a running instance of Postgres, with the respective and updated schema must be provided. This is required because thanks to SQLx during compilation steps our code issue a compilation error if our queries are not compatible with the running Postgres Schema. For further information, please refer to compile-time-verification
This step can be accomplished in various ways, I suggest to:
- Performing Migration on the host system and then executing Hasura with Docker:
- move on
hasura
folder and then start Hasura using Docker. - then, after installing Hasura-Cli you can progress applying the respective migrations.
- move on
- Performing Migration with Hasura directly from Docker, please refer to docker-compose.yml and below Docker section
cargo run
cargo build --release
./target/release/pluto-rs
What follows is a table of principal variables and some examples
Env Name | Example |
---|---|
POSTGRES_PASSWORD | "CHANGEME" |
POSTGRES_DB | pluto_db |
DATABASE_URL | postgres://postgres:pass@localhost:5432/pluto_db |
HASURA_GRAPHQL_DATABASE_URL | postgres://postgres:pass@localhost:5432/pluto_db |
HASURA_GRAPHQL_METADATA_DATABASE_URL | postgres://postgres:pass@localhost:5432/pluto_db |
HASURA_GRAPHQL_ENABLE_CONSOLE | true |
HASURA_GRAPHQL_DEV_MODE | true |
HASURA_GRAPHQL_ENABLED_LOG_TYPES | "startup, http-log, webhook-log, websocket-log, query-log" |
HASURA_GRAPHQL_ADMIN_SECRET | "myadminsecretkey" |
RUST_LOG | "exchanges=info" |
For Unit and Integration tests, execute
cargo test
For Integration tests only, execute
cargo test --test integration
Pluto can be executed from a container without any further ado.
Please take care to properly provide a working .env
file (for an exaustive list please consider: Env Variables ) and then issue:
For development
docker-compose -f docker-compose.yml -f docker-compose.dev.yml up
For testing
docker-compose -f docker-compose.yml -f docker-compose.test.yml up
request a new exchange from EUR to USD:
curl -X POST -H "Content-Type: application/json" -d '{"currencyFrom": "EUR", "currencyTo": "USD", "amount": 123}' http://localhost:3030/exchanges