A multilingual FAQ Management Solution created using FastAPI.
- FastAPI
- PostgreSQL
- Redis
- Scalability - Due to a cleaner database schema, new languages for FAQs can be added without a fuss with just a single change.
- Fast - Uses BackgroundTasks and asynchorous programming along with redis caching for querying FAQs within no time.
- Test Driven - Built with the methodology of test first and code second to ensure correct responses.
- Accurate Translation - Uses Google Cloud API directly to ensure that html tags coming from ckeditor don't cause an issue while translation.
Clone the repository:
git clone https://github.com/BlazeStorm001/FastFAQ.git
cd fastfaq
Create a new project on Google Cloud console and obtain a Service Key (json) and place it in the root of the project as gcp_cred.json.
Ensure docker is installed and run the following command:
docker-compose up --build
Access the shell of the docker container and run unit tests:
docker exec -it faq_api bash
pytest
You can access the Swagger documentation by accessing localhost:8000/docs and ensure working of endpoints
This API provides endpoints to retrieve frequently asked questions (FAQs) in multiple languages. The default language is English (en), but users can request FAQs in different languages.
GET /api/faqsRetrieves all FAQs in English.
[
{
"id": 1,
"question": "What is FastAPI?",
"answer": "FastAPI is a modern web framework for building APIs with Python.",
"language": "en"
},
{
"id": 2,
"question": "How do I reset my password?",
"answer": "Click on 'Forgot Password' and follow the instructions.",
"language": "en"
}
]GET /api/faqs/?id={faq_id}Retrieves an FAQ by its unique ID in English.
| Parameter | Type | Required | Description |
|---|---|---|---|
id |
int |
Yes | The unique ID of the FAQ |
{
"id": 1,
"question": "What is FastAPI?",
"answer": "FastAPI is a modern web framework for building APIs with Python.",
"language": "en"
}GET /api/faqs/?lang={language_code}Retrieves all FAQs in the requested language. If an FAQ is not available in the requested language, the English version is returned.
| Parameter | Type | Required | Description |
|---|---|---|---|
lang |
str |
Yes | The two-letter language code (e.g., hi for Hindi, fr for French) |
[
{
"id": 1,
"question": "फ़ास्टएपीआई क्या है?",
"answer": "FastAPI एक आधुनिक वेब फ्रेमवर्क है जो Python में APIs बनाने के लिए उपयोग किया जाता है।",
"language": "hi"
},
{
"id": 2,
"question": "त्वरित भूरी लोमड़ी आलसी कुत्ते के ऊपर से छलांग लगाती है",
"answer": "<p>त्वरित भूरी लोमड़ी आलसी कुत्ते के ऊपर से छलांग लगाती है</p>",
"language": "hi"
}
][
{
"id": 1,
"question": "What is FastAPI?",
"answer": "FastAPI is a modern web framework for building APIs with Python.",
"language": "en"
},
{
"id": 2,
"question": "त्वरित भूरी लोमड़ी आलसी कुत्ते के ऊपर से छलांग लगाती है",
"answer": "<p>त्वरित भूरी लोमड़ी आलसी कुत्ते के ऊपर से छलांग लगाती है</p>",
"language": "hi"
}
]GET /api/faqs/?id={faq_id}&lang={language_code}Retrieves an FAQ by ID in the requested language. If the requested language version is unavailable, the English version is returned. If neither is available, it returns a 404 Not Found error.
| Parameter | Type | Required | Description |
|---|---|---|---|
id |
int |
Yes | The unique ID of the FAQ |
lang |
str |
Yes | The two-letter language code (e.g., hi for Hindi, fr for French) |
{
"id": 1,
"question": "फ़ास्टएपीआई क्या है?",
"answer": "FastAPI एक आधुनिक वेब फ्रेमवर्क है जो Python में APIs बनाने के लिए उपयोग किया जाता है।",
"language": "hi"
}{
"id": 1,
"question": "What is FastAPI?",
"answer": "FastAPI is a modern web framework for building APIs with Python.",
"language": "en"
}{
"detail": "FAQ not found"
}| Status Code | Meaning | Description |
|---|---|---|
400 |
Bad Request | Invalid parameters in the request eg. wrong language code. |
404 |
Not Found | The requested FAQ ID does not exist in the database. |
PUT /api/faqs/{id}Updates an existing FAQ by its unique ID.
| Parameter | Type | Required | Description |
|---|---|---|---|
id |
int |
Yes | The unique ID of the FAQ |
{
"question": "Updated question?",
"answer": "Updated answer.",
"language": "en"
}{
"id": 1,
"question": "Updated question?",
"answer": "Updated answer.",
"language": "en"
}404 Not Foundif the FAQ ID does not exist.
DELETE /api/faqs/{id}Deletes an FAQ by its unique ID.
| Parameter | Type | Required | Description |
|---|---|---|---|
id |
int |
Yes | The unique ID of the FAQ |
204 No Contentif the deletion is successful.404 Not Foundif the FAQ ID does not exist.
Get all FAQs in English
curl -X GET "http://localhost:8000/api/faqs"Get an FAQ by ID (e.g., ID = 1)
curl -X GET "http://localhost:8000/api/faqs/?id=1"Get all FAQs in Hindi
curl -X GET "http://localhost:8000/api/faqs/?lang=hi"Get an FAQ by ID in Hindi (fallback to English if unavailable)
curl -X GET "http://localhost:8000/api/faqs/?id=1&lang=hi"- The default language is English (
en). - If a requested language version is unavailable, it falls back to the English version.
- If an FAQ ID does not exist, a
404 Not Founderror is returned.