Welcome to the Country Population Backend Server! This Kotlin-based backend server provides information on country populations and their flag images. Built using Ktor and a range of essential plugins, this server is designed to deliver efficient data retrieval for all your country-related needs.
-
Get All Countries: Retrieve a comprehensive list of all countries, including their populations and flag images.
-
Search Countries: Find a country by its name with a dedicated search endpoint.
-
Flag Images: Access flag images for any country through a dedicated endpoint (e.g.,
/images/pl.png
).
-
Ktor: A powerful framework for building web applications and APIs in Kotlin. Utilized for server setup, routing, and content negotiation.
-
Koin: Dependency Injection framework used to manage dependencies throughout the project.
-
Kotlinx Serialization: Simplifies the serialization and deserialization of data between JSON and Kotlin objects.
-
Default Headers Plugin: Automatically adds default headers, including cache control, to all responses.
-
Status Pages Plugin: Handles various HTTP status codes and exceptions in a streamlined manner.
-
Logback: Logging framework integrated for monitoring and debugging.
-
Ktor Server Tests: Framework used for testing server-side logic and endpoints.
-
Kotlin Test: Standard testing library used to write unit tests and verify functionality.
- Clone the repository:
git clone https://github.com/AdamDawi/Country-Population-Backend-Server
- Open the project in your preferred IDE.
- Ensure that the versions in gradle match those specified in the project.
- Run the server on http://localhost:8080/
Here are some examples of how the API endpoints work:
GET /countries
Returns a list of all countries with their populations and flag image URLs.
GET /countries/search?name=CountryName
Returns details for the specified country.
GET /images/{countryCode}.png
Returns the flag image for the specified country code.
- Get All Countries:
[
{
"name": "Poland",
"population": 38386000,
"flagUrl": "/images/pl.png"
},
{
"name": "Germany",
"population": 83783942,
"flagUrl": "/images/de.png"
}
...
]
- Search Country:
{
"name": "Poland",
"population": 38386000,
"flagUrl": "/images/pl.png"
}
Server returns the following status codes in its API:
Status Code | Description |
---|---|
200 | OK |
400 | BAD REQUEST |
404 | NOT FOUND |
500 | INTERNAL SERVER ERROR |
Adam Dawidziuk🧑💻