Read and display JSON results from Google Books API I’m working with the Google Books API and I’m not so sure about the way I’m going to get the search data and return it to the user. I will describe the path here and I would like to know if you would do something different.
First, I receive a search request from the user via a form inside index.html:
&lt;form action='/lookup' method=&quot;post&quot;&gt;
  &lt;input type=&quot;text&quot; name=&quot;search&quot; placeholder=&quot;Search by title, author, publisher, release, ISBN ...&quot;&gt;
  &lt;button type=&quot;submit&quot;&gt;Buscar&lt;/button&gt;
  {% block search %}{% endblock %}
&lt;/form&gt;

So in an app.py I get this request like this:
@app.route(&quot;/lookup&quot;, methods=[&quot;GET&quot;, &quot;POST&quot;])
@login_required
def search():
    &quot;&quot;&quot;Get book search.&quot;&quot;&quot;
    if request.method == &quot;POST&quot;:
        result_check = is_provided(&quot;search&quot;)
        if result_check is not None:
            return result_check
        search = request.form.get(&quot;search&quot;).upper()
        search = lookup(search)
        if search is None:
            return &quot;Invalid Search&quot;
        return render_template(&quot;search.html&quot;, search={
            'totalItems': search['totalItems'],
            'title': search['title'],
            'authors': search['authors']
        })
    else:
        return render_template(&quot;/&quot;)

Next, I access a lookup function in helpers.py:
def lookup(search):
    &quot;&quot;&quot;Look up search for books.&quot;&quot;&quot;
    # Contact API
    try:
        url = f'https://www.googleapis.com/books/v1/volumes?q={search}&amp;key=MYAPIKEY'
        response = requests.get(url)
        response.raise_for_status()
    except requests.RequestException:
        return None

    # Parse response
    try:
        search = response.json()
        return {
            &quot;totalItems&quot;: int(search[&quot;totalItems&quot;]),
            &quot;items&quot;: search[&quot;items&quot;]
        }
    except (KeyError, TypeError, ValueError):
        return None

To return the results to the user I have a search.html that is still under construction:
{% extends &quot;index.html&quot; %}

{% block search %}

&lt;p&gt;Total Items: {{search['totalItems']}}&lt;/p&gt;

&lt;table&gt;
  &lt;tr&gt;
    &lt;td&gt;
      &lt;img src=&quot;{{search['items'][0]['volumeInfo']['imageLinks']['thumbnail']}}&quot;&gt;
      &lt;p&gt;Título: {{search['items'][0]['volumeInfo']['title']}}&lt;/p&gt;
      &lt;p&gt;Autor(a): {{search['items'][0]['volumeInfo']['authors']}}&lt;/p&gt;
    &lt;/td&gt;
    &lt;td&gt;
      &lt;img src=&quot;{{search['items'][2]['volumeInfo']['imageLinks']['thumbnail']}}&quot;&gt;
      &lt;p&gt;Título: {{search['items'][2]['volumeInfo']['title']}}&lt;/p&gt;
      &lt;p&gt;Autor(a): {{search['items'][2]['volumeInfo']['authors']}}&lt;/p&gt;
    &lt;/td&gt;
  &lt;/tr&gt;
&lt;/table&gt;

{% endblock %}

Finally, my question: is this path I am following to access the API and return the data to the user the most recommended? Would you do anything other than that?
Split search() up into two functions, each accepting only one method, and dispose of your if.
There's a little bit of religion around this, but HTML5 accepts both &quot;naive HTML&quot; and XHTML-compatible tag closure, so this:
&lt;input type=&quot;text&quot; name=&quot;search&quot;&gt;

is also accepted as
&lt;input type=&quot;text&quot; name=&quot;search&quot; /&gt;

and the latter is (1) more explicit on where the tag ends and (2) is more broadly compatible.
This:
request.form.get(&quot;search&quot;).upper()

does not benefit from get, because you don't provide a default. Either allow the crash on a missing parameter, i.e. request.form['search'], or provide a default to get, likely the empty string.
This:
search = lookup(search)

is ill-advised, because it swaps types on the same symbol. The input is a string and the output is a dictionary.
This:
url = f'https://www.googleapis.com/books/v1/volumes?q={search}&amp;key=MYAPIKEY'
    

first should not hard-code your API key directly into the string, and second should not format any query parameters into the string. Instead, pass params={...} into get().
This:
except requests.RequestException:
    return None

is fairly catastrophic for the application's ability to tell maintainers and users what went wrong. You're going to want to log the exception, and translate it into an appropriate failure message returned to your own caller.
This:
requests.get(url)

should use the response in a with.
Your search.html template is deeply bizarre. Where I would expect to see a for, you've only shown the first and third items?
Ensure that you're telling the browser that your content is in Spanish.
This:
action='/lookup'

needs to use double quotes.