REST API for describing currencies and exchange rates. Provide control and management of established currencies and exchange rates, as well as calculate the conversion of arbitrary amounts from one currency to another.
The web interface of the project can be found HERE
- php 8.1
- SQLite
- Slim microframework
- Postman
- Introduction to MVC
- REST API - correct naming of resources, use of HTTP response codes
- SQL - basic syntax, table creation
- Work with Postman, test endpoints
Public Collection HERE
Getting a list of currencies. Sample response:
[
{
"id": 0,
"name": "United States dollar",
"code": "USD",
"sign": "$"
},
{
"id": 0,
"name": "Euro",
"code": "EUR",
"sign": "€"
}
]
Receiving a specific currency. Sample response:
{
"id": 0,
"name": "Euro",
"code": "EUR",
"sign": "€"
}
Adding a new currency to the database. The data is sent in the body of the request in the form of form fields (x-www-form-urlencoded
). The form fields are name
, code
, sign
. An example response is a JSON representation of a record inserted into the database, including its ID:
{
"id": 0,
"name": "Euro",
"code": "EUR",
"sign": "€"
}
Getting a list of all exchange rates. Sample response:
[
{
"id": 0,
"baseCurrency": {
"id": 0,
"name": "United States dollar",
"code": "USD",
"sign": "$"
},
"targetCurrency": {
"id": 1,
"name": "Euro",
"code": "EUR",
"sign": "€"
},
"rate": 0.99
}
]
Receive a specific exchange rate. The currency pair is specified by consecutive currency codes in the request address. Sample response:
{
"id": 0,
"baseCurrency": {
"id": 0,
"name": "United States dollar",
"code": "USD",
"sign": "$"
},
"targetCurrency": {
"id": 1,
"name": "Euro",
"code": "EUR",
"sign": "€"
},
"rate": 0.99
}
Adding a new exchange rate to the database. The data is sent in the body of the request in the form of form fields (x-www-form-urlencoded
). The form fields are baseCurrencyCode
, targetCurrencyCode
, rate
. Example form fields:
baseCurrencyCode
- USDtargetCurrencyCode
- EURrate
- 0.99
An example response is a JSON representation of a record inserted into the database, including its ID:
{
"id": 0,
"baseCurrency": {
"id": 0,
"name": "United States dollar",
"code": "USD",
"sign": "$"
},
"targetCurrency": {
"id": 1,
"name": "Euro",
"code": "EUR",
"sign": "€"
},
"rate": 0.99
}
Update the existing exchange rate in the database. The currency pair is specified by consecutive currency codes in the request address. The data is sent in the body of the request in the form of form fields (x-www-form-urlencoded
). The only form field is rate
.
An example response is a JSON representation of the updated record in the database, including its ID:
{
"id": 0,
"baseCurrency": {
"id": 0,
"name": "United States dollar",
"code": "USD",
"sign": "$"
},
"targetCurrency": {
"id": 1,
"name": "Euro",
"code": "EUR",
"sign": "€"
},
"rate": 0.99
}
Calculation of the transfer of a certain amount of funds from one currency to another. Example request - GET /exchange?from=USD&to=AUD&amount=10
.
Sample response:
{
"baseCurrency": {
"id": 0,
"name": "United States dollar",
"code": "USD",
"sign": "$"
},
"targetCurrency": {
"id": 1,
"name": "Australian dollar",
"code": "AUD",
"sign": "A€"
},
"rate": 1.45,
"amount": 10.00,
"convertedAmount": 14.50
}
Receiving an exchange rate can follow one of three scenarios. Let's say we make a transfer from currency A to currency B:
- In the
ExchangeRates
table there is a currency pair AB - take its rate - In the
ExchangeRates
table there is a currency pair BA - take its rate and calculate the reverse to get AB - In the
ExchangeRates
table there are currency pairs USD-A and USD-B - we calculate the AB rate from these rates
For all requests, in case of an error, the response may look like this:
{
"message": "Currency not found"
}
The value of message
depends on what kind of error occurred.