Please allow me to ask my question using an example where we have a database with flight data and I want to make a web app where users can search, select, and book a flight.
I wrote some classes such as SelectedFlight, Ticket, and Passenger. For example, the SelectedFlight is supposed to represent the flight that the user selects from the list of available flights. The SelectedFlight has a get_flight_data() method which queries data from the database to create the SelectedFlight object instance.
I now need to make a web app using Python Flask (which is a framework that basically lets you map URLs to Python functions).
I (think I) have two options.
(1) I create a script with some Flask functions. The user types in a URL, and the function mapped to that URL is called. The function instantiates my backend objects and returns HTML.
(2) I create a script (i.e. API) with Flask functions but instead of returning HTML, the functions will return JSON. Then I create another script with Flask functions that perform requests on the JSON URLs and render HTML for the web app.
Which of the options would you use in the example I mentioned and why?