samedi 8 décembre 2018

Rendering different response to web and android app

I saw this answer (2nd one), where it is advised to add a field (eg. device = "web") in request to decide what kind of response to be returned to a web or an android app, from a REST API.

Suggested way:

@app.route('/test', methods=['GET'])
def test():
    device = request.args.get('device')

    if device is "web":
        return render_template('test.html', data='Hello Word')
    else:
        # Return data to Android Application
        return json.dumps({'data':'Hello World'})

I found it pretty useful, however, author himself/herself says that it's a crude way to do it, and that there are better ways as well.

Please suggest me a better way, thanks.




Aucun commentaire:

Enregistrer un commentaire