Module 1 · Technical Foundations · 40 min
Technical Foundations: CLI, Git, JSON, and HTTP
Is lesson ke baad tum
CLI, Git, JSON, and HTTP form one inspectable chain: run from a known directory, version reviewed files, validate structured data, and treat every remote response as evidence to check—not magic to trust.
In this lesson
Create one small project that parses a JSON brief, inspects an HTTP response, and records a reviewed version in Git. You need Git and a supported Node.js LTS release with built-in fetch; Node 22 or newer works for this lab. Confirm git --version and node --version first. Installation time is separate from the 40-minute core.
Use only the supplied synthetic brief. The public GitHub request needs no API key; a no-network fixture route is included below.
The Four Layers and Their Jobs
The CLI runs commands in a current folder. Use Get-Location in PowerShell (pwd on macOS/Linux) when a file cannot be found. An error may describe the wrong working directory rather than a missing file.
Git records commits: snapshots of reviewed files. git status shows changed and staged files; git diff --cached shows what the next commit would contain. Git is not the same service as GitHub, and a clean working tree is not proof of correct code.
JSON stores objects, arrays, strings, numbers, booleans, and null. Keys need double quotes; comments and trailing commas are invalid. Parsing checks syntax. It will accept the string "false", even when your application needs the boolean false.
HTTP carries a method, URL, headers, optional request body, response status, and response body. Check the status and the expected body contract. JavaScript fetch resolves normally for many HTTP errors, so a returned Response is not automatically a successful result.
Worked Example: A Versioned Project Brief Inspector
Step 1: create the project and confirm where you are
Create a folder named builder-foundations, open a terminal in it, and run the commands one line at a time:
git init
npm init -y
git status
Get-LocationOn macOS or Linux, use pwd instead of Get-Location. If Git asks for your identity when you later commit, follow Git's message and configure a real name and email at the appropriate local or global scope. Do not copy somebody else's identity just to silence the warning.
Create brief.json in an editor:
{
"project": "delivery-faq-prototype",
"audience": "customers in Lahore and Islamabad",
"languages": ["English", "Roman Urdu"],
"constraints": {
"may_quote_prices": false,
"must_escalate_unknowns": true
}
}Ask Node.js to parse it before trusting it:
node -e "const fs=require('node:fs'); const x=JSON.parse(fs.readFileSync('brief.json','utf8')); console.log(x.project, x.languages.length)"Expected output is the project name followed by 2. Add a trailing comma deliberately, rerun the command, read the parse error, and then repair the file. That failure is useful: it proves the parser is checking the file you think it is checking.
Step 2: inspect an HTTP response instead of printing everything
Create inspect.mjs:
const url = "https://api.github.com/repos/openai/openai-node";
const fixtureMode = process.argv.includes("--fixture");
const response = fixtureMode
? new Response(JSON.stringify({full_name:"openai/openai-node",default_branch:"fixture-branch"}),
{status:200,headers:{"content-type":"application/json"}})
: await fetch(url, {
signal: AbortSignal.timeout(10_000),
headers: {
Accept: "application/vnd.github+json",
"User-Agent": "ai-school-foundations-lab",
},
});
console.log({
mode: fixtureMode ? "fixture" : "live",
method: "GET",
url,
status: response.status,
contentType: response.headers.get("content-type"),
});
if (!response.ok) {
throw new Error(`HTTP ${response.status}: request was not successful`);
}
if (!response.headers.get("content-type")?.includes("application/json")) {
throw new Error("Expected a JSON response");
}
const body = await response.json();
if (body.full_name !== "openai/openai-node" || typeof body.default_branch !== "string") {
throw new Error("Repository response failed the field contract");
}
console.log({ fullName: body.full_name, defaultBranch: body.default_branch });Run node inspect.mjs --fixture first: expect status 200, fullName openai/openai-node, and defaultBranch fixture-branch. This constructs a local Response; it makes no HTTP call. With internet access, node inspect.mjs makes the live public GET; its branch value comes from the actual response. Notice the gates: the program records status and content type, stops on a non-success status, parses JSON only after that, and prints two fields rather than dumping an entire response. In client work, selective logging reduces accidental exposure of personal or confidential data.
Step 3: commit a known-good state
Create .gitignore containing:
node_modules/
.env
*.logThen run:
git add brief.json inspect.mjs .gitignore package.json
git diff --cached
git commit -m "Add JSON and HTTP foundations lab"
git statusgit diff --cached is the review gate. Check that it contains no secret or private record. The final git status should report a clean working tree. A clean tree does not prove the code is correct; it proves you know which version you tested.
Failure Cases to Diagnose
Wrong directory
“file not found” may mean the terminal is in the wrong folder, not that the file vanished. Print the current directory and list files.
Invalid JSON
single quotes, comments, trailing commas, and unescaped line breaks are common causes. Use a parser, not visual inspection alone.
Valid JSON, wrong meaning
"may_quote_prices": "false"is a string, not the booleanfalse. Later lessons add schemas to catch this.HTTP failure hidden as data
check
response.okor the numeric status before treating the body as a successful result.Rate or network interruption
a timeout, DNS failure, or
429response is not evidence that your code's business logic is wrong. Record the category before deciding whether to retry.Unreviewed commit
git add .can stage local datasets or credentials. Review the staged diff and repository status every time.Remote response changed
public APIs evolve. Depend only on fields you validate and handle a missing field explicitly.
Hands-On Exercise: Produce a Reproducible Evidence Pack
Keep using the same project; do not rebuild it in another folder. Run the JSON parser and the HTTP inspector, then write the actual mode and results in a short RUNBOOK.md.
Change languages to contain only English and predict the parser's second printed value. Then add a trailing comma, observe the parse failure, and restore valid JSON. Finally change may_quote_prices from false to "false": does parsing alone reject it?
Check: one language prints 1; the trailing comma causes a syntax error; "false" still parses because it is a valid string. You need a schema or type check to reject that semantic mismatch, introduced in module 2. Restore the intended boolean before staging.
Review git diff --cached, commit only the safe project files and runbook, and record the commit identifier. If offline, run node inspect.mjs --fixture and label it response-fixture inspection, not a live HTTP success. A later optional live run should have its own recorded status.
Completion Rubric
Sources
Practice quiz
Check yourself
4 questions · practise what you just learned
1 / 4 · diagnose
The JSON parser accepts `"may_quote_prices": "false"`. Why is that insufficient for the brief?
Apna kaam check karo.
Practice complete ki? Result ko example aur lesson ke checks se compare karo.
This is your own completion record, not a graded assessment.