A compact developer-education sample for beginner JavaScript learners who can write functions and update the DOM but are new to live external data.
Learners build a browser experience that requests a random quote from the DummyJSON Quotes API, checks the HTTP response, parses JSON, selects the needed fields, and displays the result safely.
Connect familiar JavaScript skills to a reliable API workflow:
Request → Validate → Parse → Select → Display
After completing the lab, a learner should be able to:
- describe what happens between calling
fetch()and updating the page; - use Promise chaining with
.then()to work with JSON data; - check
response.okbefore trusting a response body; - identify relevant properties in an API response;
- represent loading, success, and error states in the interface;
- update untrusted text with
textContent; - evaluate AI-generated code against documentation and observed behavior.
ai-assisted-public-api-lab/
├── README.md
├── .github/
│ └── copilot-instructions.md
├── demo-starter/
│ ├── index.html
│ ├── style.css
│ └── script.js
├── demo-complete/
│ ├── index.html
│ ├── style.css
│ └── script.js
└── docs/
├── student-guide.md
└── design-rationale.md
No installation or API key is required.
- Clone or download this repository.
- Open
demo-starter/index.htmlwith a local development server. - Follow the student guide.
- Compare your decisions with
demo-complete/after you have a working attempt.
Opening the HTML file directly may work, but a local server provides a development setup closer to everyday browser work. VS Code's Live Server extension or python3 -m http.server are simple options.
The completed version intentionally stays small. Its JavaScript:
- disables the button and announces a loading state;
- sends a GET request to
https://dummyjson.com/quotes/random; - throws an error when
response.okis false; - converts the response body to JavaScript data;
- verifies that the expected text fields exist;
- writes the quote and author with
textContent; - shows a useful error message when the workflow fails;
- restores the button in
.finally().
The goal is not abstraction for its own sake. Named functions make each interface responsibility visible while the Promise chain keeps the network sequence readable.
The repository-level instructions in .github/copilot-instructions.md ask an AI coding assistant to protect the learning level and the security boundaries of the exercise.
A useful request includes:
- the learner's current experience;
- the file and TODO being addressed;
- required syntax, such as
.then()rather thanasync/await; - constraints, including vanilla JavaScript and no
innerHTML; - a request for explanation and testing guidance;
- permission boundaries for how much code the assistant should produce.
Learners remain responsible for checking the API documentation, running the code, inspecting errors, and explaining the final decisions.
- Semantic headings and a visible keyboard-focus treatment support navigation.
- A status region announces request progress and failures.
- The request button is disabled while work is pending.
response.okprevents unsuccessful HTTP responses from being treated as successful data.- Response fields are checked before display.
textContentprevents API-provided text from being interpreted as HTML.- The interface preserves a clear message when the network or response shape fails.
This portfolio sample is an independently reconstructed developer-education artifact based on a live learning experience I previously designed and facilitated. All public wording, code, repository structure, and supporting materials were created anew. Employer branding, proprietary curriculum, internal links, learner information, and original contracted materials are not included.
The sample uses the public DummyJSON service for educational prototyping. It is not affiliated with or endorsed by DummyJSON.