This project is a Node.js RESTful API that communicates with the Calendarific API to retrieve holiday information for specific countries and years. It uses caching to minimize API calls and improve performance.
-
Clone the Repository:
git clone https://github.com/mian-ali/node-calendar-api.git cd node-calendar-api
-
Install Dependencies:
npm install
-
Set Up Environment Variables: Create a
.env
file in the root of the project and add the following variables:CALENDARIFIC_API_KEY=your_calendarific_api_key CACHE_TTL=3600 PORT=3000
-
Run the Application:
npm start
The API will be running at
http://localhost:3000
.
To run Redis using Docker, follow these steps:
-
Pull Redis Image: Run Redis Stack with Web UI (for exploring data):
docker run -d --name redis-stack-server -p 6379:6379 -p 8001:8001 redis/redis-stack-server:latest
Access the Redis Stack Web UI at
http://localhost:8001
.
Retrieve holidays for a specific country and year.
GET /api/holidays?country=PK&year=2024
country
: The ISO 3166-1 alpha-3 country code (e.g.,PK
for Pakistan).year
: The year for which to retrieve holidays (e.g.,2024
).
[
{
"name": "Eid ul-Fitr",
"date": "2024-04-10",
"observed": "2024-04-10"
},
...
]
Retrieve the list of supported countries.
GET /api/countries
[
{
"iso": "PAK",
"name": "Pakistan"
},
...
]
- Node.js: Ensure Node.js is installed on your machine.
- Docker: For running Redis in a container.
- Redis: Used for caching API responses to improve performance.
- Ensure Redis is running before starting the application to avoid connectivity issues.
- Use the
.env
file to securely manage environment variables, especially the Calendarific API key.