Skip to content

A RESTful API that fetches country data from an external API, stores it in a database, and provides CRUD. operations.

Notifications You must be signed in to change notification settings

brainox/CountryCurrencyExchangeAPI

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Country Currency Exchange API

A RESTful API built with Go (Gin framework) that provides information about countries, their currencies, and estimated GDP based on population and exchange rates.

Features

  • Fetch and store country data from external APIs
  • Real-time exchange rate integration
  • GDP estimation based on population and exchange rates
  • Filter countries by region or currency
  • Sort countries by estimated GDP
  • Visual summary generation
  • In-memory data storage with refresh capability

API Endpoints

Status

GET /status

Returns the total number of countries in the database and last refresh timestamp.

Countries

Refresh Data

POST /countries/refresh

Fetches fresh data from external APIs and updates the database.

Get All Countries

GET /countries

Returns all countries. Supports the following query parameters:

  • region: Filter by region (e.g., Africa, Europe)
  • currency: Filter by currency code (e.g., NGN, USD)
  • sort: Sort by GDP (gdp_asc or gdp_desc)

Examples:

GET /countries?region=africa
GET /countries?currency=ngn
GET /countries?sort=gdp_desc
GET /countries?region=africa&sort=gdp_desc

Get Country by Name

GET /countries/:name

Returns details for a specific country.

Example:

GET /countries/Nigeria

Delete Country

DELETE /countries/:name

Removes a country from the database.

Summary Image

GET /summary/image

Returns a visual summary of the database including total countries and top 5 countries by GDP.

Data Sources

Response Format

Country Object

{
    "id": 1,
    "name": "Nigeria",
    "capital": "Abuja",
    "region": "Africa",
    "population": 206139589,
    "currency_code": "NGN",
    "exchange_rate": 1600.23,
    "estimated_gdp": 25767448125.2,
    "flag_url": "https://flagcdn.com/ng.svg",
    "last_refreshed_at": "2025-10-22T18:00:00Z"
}

Running the Application

  1. Clone the repository
  2. Navigate to the project directory
  3. Run the application:
go run .
  1. The API will be available at http://localhost:8080

Development Notes

  • Built with Go 1.x and Gin web framework
  • Uses in-memory storage (can be extended to use a database)
  • Generates visual summaries using the gg graphics library
  • Case-insensitive search and filtering
  • Automatic timestamp management for data freshness

Future Enhancements

  • Database integration for persistent storage
  • User authentication and rate limiting
  • Additional filtering options
  • Historical exchange rate data
  • More detailed country statistics
  • Caching layer for improved performance

License

MIT License - feel free to use this project for learning or building upon it.

About

A RESTful API that fetches country data from an external API, stores it in a database, and provides CRUD. operations.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published