Hi
How can I specify a parameter to task 1.
I have a task list, which is triggered by an integer (1 or 2). But in addition to the integer, I would like to pass in additional parameters, not necessarily number types.
This is what I currently have:
Sample output:
How can I specify a parameter to task 1.
I have a task list, which is triggered by an integer (1 or 2). But in addition to the integer, I would like to pass in additional parameters, not necessarily number types.
This is what I currently have:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
#!/usr/bin/python3 from flask import Flask, jsonify, json import cx_Oracle con = cx_Oracle.connect( 'ordb/ordb@//10.11.12.18:1521/FTNODE' ) app = Flask(__name__) tasks = [ { 'id' : 1 , 'title' : 'Customer list' , 'description' : 'List of customers currently in the database' , 'done' : False }, { 'id' : 2 , 'title' : 'Warehouse List' , 'description' : 'List of warehouses currently in the database' , 'done' : False } ] @app .route( '/warehouse/api/v1.0/api' , methods = [ 'GET' ]) def get_tasks(): return jsonify({ 'tasks' : tasks}) @app .route( '/warehouse/api/v1.0/api/<int:task_id>' , methods = [ 'GET' ]) def get_task(task_id): task = [task for task in tasks if task[ 'id' ] = = task_id] if len (task) = = 0 : abort( 404 ) print (task_id) if task_id = = 1 : c = con.cursor() query = 'select * from customer' result = list (c.execute(query)) c.close() jsonData = json.dumps(result) print (task_id) if task_id = = 2 : c = con.cursor() query = 'select * from warehouse' result = list (c.execute(query)) c.close() jsonData = json.dumps(result) return jsonify({ 'task' : jsonData}) if __name__ = = '__main__' : app.run(port = 5001 ,debug = False ) con.close() |
1 2 3 4 5 6 7 8 |
$ curl - i http: / / 127.0 . 0.1 : 5001 / warehouse / api / v1. 0 / api / 1 HTTP / 1.0 200 OK Content - Type : application / json Content - Length: 332 Server: Werkzeug / 0.14 . 1 Python / 3.6 . 5 Date: Thu, 21 Jun 2018 13 : 41 : 30 GMT { "task" : "[[41, \"Aaron\", \"A.\", \"Aaronson\"], [42, \"Diana\", null, \"Birch\"], [43, \"David\", \"C.\", \"Pack\"], [44, \"Hakim\", null, \"Dogan\"], [45, \"Anita\", null, \"Eaton\"], [46, \"Jasmin\", null, \"Faraday\"], [47, \"Gene\", \"B.\", \"McClene\"], [48, \"Todd\", null, \"Howard\"], [49, \"Irma\", null, \"Howitzer\"]]" } |