title: Calling REST API from the same server
body: <p>I have a web application which is backed by REST API located on the same server. Let's say I have a <code>Task</code> resource accessible on <code>/api/task/&lt;task_id&gt;</code> and a web page <code>/create-task</code> which is basically just a form to create a task. There are several ways how to do it:</p>
  
  <p>a) Communicate with REST API using Javascript (don't want to do that)</p>
  
  <p>b) Create object directly in a database</p>
  
  <pre><code>@app.route('/create-task', methods=['POST'])
  def create_task(self):
      # create an object
      try:
          task = Task(request.form)
      except:
          # handle errors and put them to form
          pass
      # save it into db
      task.save()
  </code></pre>
  
  <p>c) call REST API using <code>requests</code> library</p>
  
  <pre><code>@app.route('/create-task', methods=['POST'])
  def create_task(self):
      # send request to REST API
      r = requests.post(url_for('api.task', _external=True), json=request.form.data)
      if r.status_code != 200:
          # handle errors and put them to form
          pass
  </code></pre>
  
  <p>What option would you consider to be the best practice? Think of issues associated with error handling and forms.</p>
  
  <p>Bonus question concerning <code>flask-restful</code>. Let's say I have already a working API built with flask-restful and want to use option b). Can I somehow use <code>TaskResource.post</code> to do that?</p>