- Go to the link https://date.nager.at/Api
- Check out the example API which returns the public holidays from a given year and country.
- 2017/AT
- Click on API documentation
- Expand /api/v3/AvailableCountries
- Click on try it out and execute
- A list of available countries is returned from this public API
- Expand /api/v3/PublicHolidays/{year}/{countryCode}
- Click on try it out and fill the form
- year: 2017
- countryCode: AT
- Click on Execute. The lsit of holidays is returned
- Now let us call this public API from our Express APP and insert data into the database
- Navigate to the foler from terminal
$ cd /WORKSHOP/WebApp-Workshop1/holiday-app/
- Initalize postgres
$ sudo docker-compose up -d postgres
- Import database schema and create tables
$ sudo docker exec -i postgres14-db psql -U node_user -d holiday_db < schema/holiday.sql
- You should see a message CREATE TABLE
- Open new terminal & login to the databse using password
$ sudo docker exec -it postgres14-db psql -U node_user -d holiday_db
- Check if all the tables are loaded
holiday_db=# \d
- You should see all the relations
- Open another terminal from the same file location run the follwing command (Use this terminal to monitor the docker-compose logs)
$ sudo docker-compose up
- You should see a message on the terminal
- ⚡️[server]: Server is running at http://localhost:3000
- Open
http://localhost:3000/
in your browser - You should see following message
{"message":"Express + TypeScript Server",
"dbResult":[{"now":"2022-08-16T09:24:50.246Z"}]}
- Access the available app API through curl command open new terminal
- GET /
Output will be as followscurl http://localhost:3000/ | jq '.'
{ "message": "Express + TypeScript Server", "dbResult": [ { "now": "2022-08-16T11:05:59.274Z" } ] }
- GET /country-list
Output :curl http://localhost:3000/country-list | jq '.'
[ { "countryCode": "AD", "name": "Andorra" }, { "countryCode": "AL", "name": "Albania" }, ...
- Bring down the application by down command
- Run the below command from the directory location #/WORKSHOP/WebApp-Workshop1/holiday-app/
sudo docker-compose down