title: How to make a simple Python REST server and client?
body: <p>I'm attempting to make the simplest possible REST API server and client, with both the server and client being written in Python and running on the same computer.</p>
  
  <p>From this tutorial:</p>
  
  <p><a href="https://blog.miguelgrinberg.com/post/designing-a-restful-api-with-python-and-flask" rel="noreferrer">https://blog.miguelgrinberg.com/post/designing-a-restful-api-with-python-and-flask</a></p>
  
  <p>I'm using this for the server:</p>
  
  <pre><code># server.py
  
  from flask import Flask, jsonify
  
  app = Flask(__name__)
  
  tasks = [
      {
          'id': 1,
          'title': u'Buy groceries',
          'description': u'Milk, Cheese, Pizza, Fruit, Tylenol',
          'done': False
      },
      {
          'id': 2,
          'title': u'Learn Python',
          'description': u'Need to find a good Python tutorial on the web',
          'done': False
      }
  ]
  
  @app.route('/todo/api/v1.0/tasks', methods=['GET'])
  def get_tasks():
      return jsonify({'tasks': tasks})
  
  if __name__ == '__main__':
      app.run(debug=True)
  </code></pre>
  
  <p>If I run this from the command line:</p>
  
  <pre><code>curl -i http://localhost:5000/todo/api/v1.0/tasks
  </code></pre>
  
  <p>I get this:</p>
  
  <pre><code>HTTP/1.0 200 OK
  Content-Type: application/json
  Content-Length: 317
  Server: Werkzeug/0.16.0 Python/3.6.9
  Date: Thu, 05 Mar 2020 02:45:59 GMT
  
  {
    "tasks": [
      {
        "description": "Milk, Cheese, Pizza, Fruit, Tylenol", 
        "done": false, 
        "id": 1, 
        "title": "Buy groceries"
      }, 
      {
        "description": "Need to find a good Python tutorial on the web", 
        "done": false, 
        "id": 2, 
        "title": "Learn Python"
      }
    ]
  }
  </code></pre>
  
  <p>Great, now my question is, how can I write a Python script using requests to obtain the same information?</p>
  
  <p>I suspect this is the proper idea:</p>
  
  <pre><code># client.py
  
  import requests
  
  url = 'http://todo/api/v1.0/tasks'
  
  response = requests.get(url,
                          # what goes here ??
                          )
  
  print('response = ' + str(response))
  </code></pre>
  
  <p>However as you can see from my comment, I'm not sure how to set up the parameters for <code>requests.get</code>.</p>
  
  <p>I attempted to use this SO post:</p>
  
  <p><a href="https://stackoverflow.com/questions/17301938/making-a-request-to-a-restful-api-using-python">Making a request to a RESTful API using python</a></p>
  
  <p>as a guideline however it's not clear how to adjust the formatting per the message change.</p>
  
  <p>Can provide a brief description of how to set up params to pass into <code>requests.get</code> and suggest the necessary changes to get the client example above working?  Thanks!</p>
  
  <p>--- Edit --- </p>
  
  <p>Something else I can mention is that I got the client to work using Postman pretty easily, I'm just not sure how to set up the syntax in Python:</p>
  
  <p><a href="https://i.stack.imgur.com/UZTO8.png" rel="noreferrer"><img src="https://i.stack.imgur.com/UZTO8.png" alt="enter image description here"></a></p>
  
  <p>--- Edit ---</p>
  
  <p>Based on icedwater's response below, this is complete, working code for the client:</p>
  
  <pre><code># client.py
  
  import requests
  import json
  
  url = 'http://localhost:5000/todo/api/v1.0/tasks'
  
  response = requests.get(url)
  
  print(str(response))
  print('')
  print(json.dumps(response.json(), indent=4))
  </code></pre>
  
  <p>result:</p>
  
  <pre><code>&lt;Response [200]&gt;
  
  {
      "tasks": [
          {
              "description": "Milk, Cheese, Pizza, Fruit, Tylenol",
              "done": false,
              "id": 1,
              "title": "Buy groceries"
          },
          {
              "description": "Need to find a good Python tutorial on the web",
              "done": false,
              "id": 2,
              "title": "Learn Python"
          }
      ]
  }
  </code></pre>