python+flask实现服务器:
安装python和flask略过,servicestest.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)
命令行下:python servicestest.py
之后浏览器:http://127.0.0.1:5000/todo/api/v1.0/tasks就可以看到运行的结果
运行结果:
{
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"
}
]
}
建议使用curl:
curl -i http://localhost:5000/todo/api/v1.0/tasks
运行结果:
虽然很简单,毕竟是第一次能运行,还是记录鼓励下自己。
参考:http://www.cnblogs.com/vovlie/p/4178077.html