Skip to content

Pluto is a RESTful app that can accept and convert "currency" values uploaded by the user.

License

Notifications You must be signed in to change notification settings

nidble/pluto-rs

Repository files navigation

Pluto

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.

Tech

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.

TLDR

  • After executing the RESTful server a route capable to perform the currency conversion will be exposed at <basePath>/exchanges by issuing a POST 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.

Installation

Pluto requires Rust v1.56+ toolchain, Hasura v2+, and Postgres v14+ to run.

Prerequisites

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.
  • Performing Migration with Hasura directly from Docker, please refer to docker-compose.yml and below Docker section

Server compilation and execution

for development:

cargo run

for production:

cargo build --release
./target/release/pluto-rs

Enviromental variables

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"

Testing

For Unit and Integration tests, execute

cargo test

For Integration tests only, execute

cargo test --test integration

Docker

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

Curl Examples

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

License

MIT

About

Pluto is a RESTful app that can accept and convert "currency" values uploaded by the user.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published