- Docker locally.
- Git installed locally.
- PHP installed locally.
- Composer installed locally.
- An API Access Key tied to a valid account in fixer.io subscribed to the basic plan.
- Before starting, you should ensure that no other web servers or databases are running on your local computer.
- Clone the repository locally with
git clone git@github.com:JesusGarciaValadez/Currency-Converter-API.git. - Accessing to the repository with
cd Currency-Converter-API; - Copy the
.env.examplefile as.envand.env.testingfiles. - Replace the following values in the
.envfile:
APP_NAME=
APP_URL=
...
DB_DATABASE=
DB_USERNAME=
DB_PASSWORD=
...
FIXER_API_KEY=
- For the
APP_URLyou can use thehttp://localhost. - For the
.env.testingfile, you can leave the current values if you want. - You can use wherever values do you want to use for the database setup.
- You need your Fixer's API Access Key for the
FIXER_API_KEYenvironment variable.
- Install the composer dependencies with
composer install; - Run the command
php artisan sail:installto publish the necessary for Docker to run. - Create the Docker container using
./vendor/bin/sail up -dfor the detached mode. - This will create the container using some environment variables of your
.envfile.
Once the container was created and running, you have to run the following commands:
./vendor/bin/sail artisan key:generate;
./vendor/bin/sail artisan migrate:fresh;
./vendor/bin/sail artisan migrate:fresh --env=testing;
You can access the API through http://localhost/api/currency/conversion endpoint.
You can run the following command ./vendor/bin/sail test.
You can access the database using 127.0.0.1 as host and the same values for the DB_USERNAME, DB_PASSWORD, and DB_USERNAME stored in your .env file.
You can stop the containers using ./vendor/bin/sail down.
You need to recreate the container running docker-compose build, or stop the containers and images, delete them, and run ./vendor/bin/sail up -d to download the images again and rebuild them.
The only endpoint available is a POST request to /api/currency/conversion. The payload accepted is something like the following:
{
"source_currency": "USD",
"target_currency": "DKK",
"value": "1000",
}
All the fields are mandatory to get a proper response like the following:
{
...
"source_currency": "USD",
"target_currency": "DKK",
"value": "1000",
"amount_converted": "6247.66",
"rate": "6.24766",
"timestamp": "1615934226",
...
}
If any of the fields are missed, or any of the currency fields have an invalid currency, then you'll have an error.
You can see the result of the API deployed to production