This functionality should go in `api.js`.