Overview

The Countries Info API is a Rest API built in python with flask, I scraped countries info data like: name, capital, population, area from Scrapethissite, then saved them in a PostgreSQL database.

The api has 3 GET, 3 POST and 1 PUT enpoints, the POST endpoints can be used to add a country code, iso code, and fun fact. The PUT endpoint can be used to edit a country fun fact


Database Schema

db_schema
Endpoints

All countries

GET http://127.0.0.1:5000/allcountries

Method: GET, param: /allcountries, return all the countries and their info from the database


Number of countries

http://127.0.0.1:5000/getcountries/

return the number of countries passed in the request.

Method: GET, param: getcountries/number, number:int

eg: bellow return 2 countries: http://127.0.0.1:5000/getcountries/2

                [
                    {
                        "id": 1,
                        "country_name": "Andorra",
                        "country_capital": "Andorra la Vella",
                        "contry_population": 84000,
                        "country_area": 468.0,
                        "country_code": 376,
                        "iso_code": null
                    },
                    {
                        "id": 2,
                        "country_name": "United Arab Emirates",
                        "country_capital": "Abu Dhabi",
                        "contry_population": 4975593,
                        "country_area": 82880.0,
                        "country_code": 971,
                        "iso_code": null
                    }
                ]
            

Country info by name

http://127.0.0.1:5000/getcountry/

return a country info using its name

Method: GET, param: getcountry/countryName: eg: getcountry/niger

eg: http://127.0.0.1:5000/getcountry/niger

                [
                    {
                        "id": 162,
                        "country_name": "Niger",
                        "country_capital": "Niamey",
                        "contry_population": 15878271,
                        "country_area": 1267000.0,
                        "country_code": 227,
                        "iso_code": "NE/NER"
                    }
                ]
            

Add country code

http://127.0.0.1:5000/add_country_code

Method: POST :param: required: country_name:string, country_code:int

eg: http://127.0.0.1:5000/add_country_code?country_name=armenia&country_code=374

                [
                    "success",
                    {
                        "id": 7,
                        "country_name": "Armenia",
                        "country_capital": "Yerevan",
                        "contry_population": 2968000,
                        "country_area": 29800.0,
                        "country_code": 374,
                        "iso_code": null
                    }
                ]
            

If the country code is alredy filled it returns:

                [
                    "Country code already filled",
                    {
                        "id": 7,
                        "country_name": "Armenia",
                        "country_capital": "Yerevan",
                        "contry_population": 2968000,
                        "country_area": 29800.0,
                        "country_code": 374,
                        "iso_code": null
                    }
                ]
            

Add country iso code

http://127.0.0.1:5000/add_country_iso_code

Method: POST :param: required: country_name:string, iso_code:string

eg: http://127.0.0.1:5000/add_country_iso_code?country_name=Austria&iso_code=AT/AUT

                [
                    "success",
                    {
                        "id": 12,
                        "country_name": "Austria",
                        "country_capital": "Vienna",
                        "contry_population": 8205000,
                        "country_area": 83858.0,
                        "country_code": null,
                        "iso_code": "AT/AUT"
                    }
                ]
            

If the country iso code is alredy filled it returns:

                [
                    "Country already has a funfact",
                    {
                        "id": 24,
                        "country_name": "Burundi",
                        "country_capital": "Bujumbura",
                        "country_population": 9863117,
                        "country_area": 27830.0,
                        "country_code": null,
                        "iso_code": null,
                        "fun_fact": "Burundi one of the okest country hehe"
                    }
                ]
            

Add country fun fact

http://127.0.0.1:5000/add_fun_fact

Method: POST :param: required: country_name:string, fun_fact:string (max lenght 250)

eg: http://127.0.0.1:5000/add_fun_fact?country_name=Angola&fun_fact=At 105 metres high and 400 metres wide, the Kalandula waterfalls is a spectacular waterfall in Angola. It is Africas second largest waterfall, after Victoria falls. It’s a five hours drive from Luanda, in Malanje province.

                [
                    "Success",
                    {
                        "id": 8,
                        "country_name": "Angola",
                        "country_capital": "Luanda",
                        "country_population": 13068161,
                        "country_area": 1246700.0,
                        "country_code": null,
                        "iso_code": null,
                        "fun_fact": "At 105 metres high and 400 metres wide, the Kalandula waterfalls is a spectacular waterfall in Angola. It is Africas second largest waterfall, after Victoria falls. Its a five hours drive from Luanda, in Malanje province."
                    }
                ]
            

Edit country fun fact

http://127.0.0.1:5000/edit_fun_fact

Method: PUT: :param: country_name:string, new_fun_fact:string (max lenght 250)

eg: http://127.0.0.1:5000/edit_fun_fact?country_name=Burundi&new_fun_fact=Burundi one of the okest country hehe

                {
                    "SUCESS": {
                        "Old fun fact": "Burundi one of the okest country hehe",
                        "New fun fact": "Burundi is may fav country"
                    }
                }