Connecting the Halves

Both halves work. The join is where the time goes.

The usual culprits, all of them boring and all of them expensive to diagnose blind: CORS, cookies not being sent, a trailing slash, a field named first_name on one side and firstName on the other, dates as strings in one format and parsed as another, and a 404 page returned as HTML to something expecting JSON.

Agree the contract once and write it down. Field names, casing, date format, what an error looks like, what an empty result looks like.

The most valuable half hour in this phase is the one where you write out the exact JSON of one successful response and one error, and then make both sides match it. Doing it verbally means discovering the mismatch three days later inside a component.

◈ Graded Challenge

Write handle(status, body) turning a response into what the interface should show. Return a dictionary with a state key and, where relevant, a message or items key. For status 200 with a body containing a non-empty results list, return {"state": "ready", "items": the list}. For 200 with an empty results list, return {"state": "empty"}. For 401 return {"state": "signin"}. For 403 return {"state": "error", "message": "You do not have access to that."}. For 404 return {"state": "missing"}. For anything 500 or above return {"state": "error", "message": "Something went wrong. Please try again."}.

Name it exactly: handle(status, body)

Python3 visible + 5 hidden
loading editor…

Mark this lesson complete

Signed in, your progress follows you to every device.

Next: Authentication Across the Join →
← Back