Project 2: API-based Dictionary App0%

Project 2: API-based Dictionary App

Beginner12 min readUpdated: Jul 11, 2026
Study Materials

Project 2: API-Based Dictionary & Vocab Builder in Python

In this intermediate project, we apply modern HTTP networking and local state persistence—HTTP Requests with requests, JSON Parsing, Exception Handling, and File Serialization with json—to construct a feature-complete Command-Line Dictionary & Vocabulary Builder.


1. System Architecture & API Specification

The application integrates with the open, public Free Dictionary API (https://api.dictionaryapi.dev/api/v2/entries/en/<word>).

Key Capabilities:

  1. 1
    Live Lexical Lookup: Queries word definitions, parts of speech, phonetic pronunciations, example usages, and synonyms.
  2. 2
    Local Vocabulary Persistence (vocabulary.json): Automatically caches looked-up words locally so users can review vocabulary even when offline.
  3. 3
    Interactive Flashcard Mode: Quizzes the user on previously saved vocabulary words to reinforce learning.
  4. 4
    Resilient Network Handling: Handles HTTP 404 Not Found (unknown words), connection errors, and malformed JSON payloads gracefully.

2. Complete Project Implementation

Visual Architecture & Process Flow

How data and code flow step-by-step

Flowchart
Step 1
def _load
self
Step 2
Dict[str, Any]:

3. Sample Execution Simulation

Output
===== DICTIONARY & VOCABULARY BUILDER =====
1. Look Up a Word
2. View Saved Vocabulary
3. Test Knowledge (Flashcards)
4. Exit
Select an option (1-4): 1
 
Enter word to look up: resilient
 
=======================================================
WORD: RESILIENT (/rɪˈzɪl.jənt/)
=======================================================
 
[ADJECTIVE]
1. Able to endure tribulation or recover quickly from shock, illness, or other adversity.
* Example: "The community remained resilient after the flood."
2. Returning to its original shape after being compressed or stretched.
* Synonyms: tough, hardy, robust
=======================================================

Multiple Choice Questions

1. In this application, how is offline functionality achieved for words previously searched?

A. By downloading the entire Oxford English Dictionary on startup B. By checking the local vocabulary.json cache before making any HTTP request C. By keeping the computer connected to Bluetooth D. Offline lookup is not supported Answer: B Explanation: The client checks if the word is already stored in self.vocab_mgr.vocab (loaded from vocabulary.json); if present, it loads the cached definition without hitting the network.


2. How does the application identify when a queried word does not exist in the dictionary?

A. The API server returns HTTP status code 404 Not Found B. Python throws an IndexError C. The terminal closes D. The API returns a 500 error Answer: A Explanation: The Free Dictionary API returns an HTTP 404 Not Found status when a word cannot be found in the English lexicon.


3. Which method in Python's json module saves the vocabulary dictionary to disk?

A. json.loads() B. json.dump() C. json.write() D. json.export() Answer: B Explanation: json.dump(obj, file) serializes a Python data structure directly into a writable file stream.


4. Why does lookup_word() clean the input using .strip().lower()?

A. Because JSON keys cannot store capital letters B. To ensure case-insensitive consistency and eliminate accidental whitespace in API queries and dictionary lookups C. To convert strings into numbers D. It is required by PEP 8 Answer: B Explanation: Normalizing user strings with .strip().lower() guarantees reliable cache matching and prevents malformed URLs.


5. What random selection function is used in Flashcard mode to select a random saved word?

A. random.randint() B. random.choice() C. random.shuffle() D. random.uniform() Answer: B Explanation: random.choice(sequence) picks a single random element from a non-empty sequence.


Next Lesson

Project 3: CLI-based To-do App

Continue learning with hands-on practice, examples, and exercises in the upcoming topic.

Practice Quiz

Test your understanding of this lesson with 5 questions. Each question has one correct answer.

PrevNext