Homework
Homework — your key and your data
Homework — your key and real data.
- Create
js/api.jswithrequest()(with theresponse.okcheck) andfetchPictures(days). AddformatDateParamtoutils.js. Makemain.jsan asyncload(). - Load real pictures. Serve it and check: "Loaded 14 pictures. Newest: …". That's real NASA data now.
- Get your own key. api.nasa.gov → sign up (free) → put your key in
config.jsinstead ofDEMO_KEY. Now reload as much as you like — the limit won't bite. - Reproduce the
response.oktrap. Temporarily break the URL (e.g.apod→apodX). With theresponse.okcheck you get a clear "The API returned 404". Comment the check out — you get a cryptic JSON parse error (because you're reading an error page as JSON). Restore the check.
Required tests:
- Load test: with a working key you see real pictures.
response.oktest: a broken URL gives a clear status, not a JSON crash.
To submit: screenshots: (1) "Loaded … Newest: …" with your key, (2) The API returned 404 with a broken URL.
Next. We have real data — but only as text. In lesson 5 we arrange it into a gallery: many cards in a grid, efficiently (DocumentFragment), with lazily-loaded images (IntersectionObserver).