This project implements a "Hello World" API and a web interface for interacting with it. The API returns "Hello World" messages in multiple languages based on a query parameter, and the web interface allows users to select a language and display the appropriate greeting message.
The initial version supported a basic "Hello World" API that returned greeting messages in English, French, and Hindi.
This version introduces the following enhancements:
- Dynamic Language Support:
- Added a /languages endpoint to fetch available languages dynamically.
- Languages are stored in an external languages.json file, simplifying the addition of new languages.
- Dynamic API Link Handling:
- Frontend now fetches API links from a config.json file, making it resilient to backend URL/IP changes.
- Improved Scalability:
- Adding a new language requires only an update to languages.json without modifying the backend or frontend code.
-
hello_world_api.py: Flask-based backend API (Version 1).
-
hello-world-app/: React app for frontend (Version 1).
-
index.html: Basic HTML hosting for the V1 app.
-
surajw141-hello-world-api-v1.zip: Archived files for V1.
-
hello_world_api.py: Flask-based backend API (Enhanced Version).
-
languages.json: External file containing language data for scalability.
-
hello-world-app/: React app for frontend (Enhanced Version).
-
V2-surajw141-hello-world-api.zip: Archived files for V2.
- Python 3.7+: Ensure Python 3.7 or higher is installed. You can download it from Python's official website.
- Flask: A Python web framework to run the API server.
- Flask-CORS (optional): If you plan to deploy the frontend and backend separately, this will enable Cross-Origin Resource Sharing (CORS).
- Node.js (16+ recommended): Install Node.js and npm (comes bundled with Node.js) from Node.js official website.
sudo apt install -y nodejs
git clone <https://github.com/surajw141/hello-world-api.git>
cd hello-world-appcd "Hello World API V2"python3 -m venv venv
source venv/bin/activate pip install flask flask-cors python-dotenv requests
python3 hello_world_api.py Navigate to your frontend folder and install dependencies.
cd hello-world-app
npm install
npm start-
Update languages.json:
Add the new language and greeting to languages.json. For example, to add Marathi:
{
"Marathi": "Namaskar Jag"
}
-
Frontend Updates:
No changes required; the dropdown updates dynamically.
-
Backend Updates:
The API automatically supports the new language via the /languages and /message endpoints.
-
Replaced hardcoded API links in the React frontend with a config.json file located in public folder.
{ "api_base_url": "http://192.168.6.5:5000" } -
This ensures that if the backend IP or URL changes, the frontend automatically adapts without manual code changes.
- Open the browser and navigate to the React app at http://localhost:3000.
- Select a language from the dropdown to see the greeting message.
This enhanced version ensures better scalability and ease of maintenance while preserving all functionality from the previous version.