Lesson 04 · Backend & Servers
Persistence: Files & Databases
Memory forgets everything at the next restart. Give your API data that outlives the process - first a JSON file written atomically, then real SQL with SQLite - all behind a repository seam that keeps the API itself untouched.
Prerequisites: REST APIs & JSON over HTTP
Learning objectives
By the end of this lesson, you will be able to:
- Persist an API's data across restarts by loading a JSON file at boot and saving it after every change
- Write files without the torn-write failure mode, using the tmp-file-and-rename atomic pattern
- Read and write basic SQL - INSERT, SELECT, UPDATE, DELETE - with values passed through prepared statements only
- Hide storage behind a repository module so route handlers never care where the data lives