Git Product home page Git Product logo

currency-api's Introduction

Currency exchange rates API

This is a simple REST API that provides exchange rates for the specified list of currencies. The exchange rates are obtained from the currencyfreaks.com API and saved in a SQLite database.

Prerequisites

Put an API key for the currencyfreaks.com API in the config.ini file:

apikey = your_api_key

or pass it as a command line argument:

./bin/api --apikey your_api_key

or set it as an environment variable:

APIKEY=your_api_key ./bin/api

Docker build and run

Correct API key should be put in the config.ini file before building the docker container.

To build and run the docker container:

docker build -t currency-api .
docker run -it --rm -p 8080:8080 currency-api

API will be available at http://localhost:8080/

Local build and run

make && ./bin/api

Will start the API server on port 8080

Configuration

The configuration file is config.ini in the root of the project - it contains default settings which can be overridden by environment variables or command line arguments:

make && ./bin/api --apikey your_api_key --port 8081 --dbpath /tmp/currency-api.db --currencies UAH,USD,EUR,RON --debug

Full list of configuration options can be listed with make && ./bin/api --help

Database

The database is created in the file specified in the configuration file. The database schema with sample data is created automatically on the first run of the API server.

Logging

The API logs all requests to the database. Last 10 logs can be viewed with the /v1/status/ endpoint.

Testing

make test

Runs all available tests

API endpoints

/v1/rates/ - get latest exchange rates for the currencies specified in the config file

{
	"date": "2024-04-30 00:00:00",
	"base": "USD",
	"rates": {
		"EUR": 0.933291146848332,
		"RON": 4.642474983710198,
		"UAH": 39.63845919120639,
		"USD": 1
	}
}

/v1/rates/<date>/ - get exchange rates for the specified date (e.g. 2024-04-20)

{
	"date": "2024-04-20 00:00:00",
	"base": "USD",
	"rates": {
		"EUR": 0.8,
		"RON": 4.7,
		"UAH": 39.4
	}
}

/v1/pair/<pair>/ - get exchange rates for the specified currency pair (e.g. UAH-RON)

{
	"date": "2024-04-30",
	"pair": "UAH-RON",
	"rate": 0.11712047033200801
}

/v1/status/ - get the status of the API

{
	"status": "ok",
	"version": "93952c1-main-20240501",
	"config": {
		"port": 8080,
		"dbpath": "file:/tmp/currency-api.db?mode=rwc\u0026_journal_mode=WAL",
		"currencies": "UAH,USD,EUR,RON",
		"interval": 3600,
		"debug": true
	},
	"logs": [
		"2024-05-01 01:45:39 | pair | pair: UAH-RON"
	]
}

Original job interview test task:

Implement a REST API with the following functionality

  1. Obtaining exchange rates on a third-party API (UAH / EUR / USD / RON). (eg: https://currencyfreaks.com/)

    1.1 If there was no exchange rate for the current day, get the exchange rate updated at 12:00

    1.2 Implement saving the exchange rate in the database (Sqlite for start, PostgreSQL for extra points)

  2. Implement endpoints:

    2.1. Receiving rates for a specified date (all 4 currencies)

    2.2. Obtaining currency pairs: UAH-USD.

  3. Implement validation of requests (dates, currency tickers)

  4. Implement API access via API key

  5. Implement logging of API requests in the database. Save in the logs - date, type of request (by date / by pair)

  6. Use docker for the project.

  7. When initializing the server, fill the database with initial data on exchange rates for several dates (any values)

currency-api's People

Contributors

parmaster avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.