美文网首页
构建Web API

构建Web API

作者: stonkerlee | 来源:发表于2016-12-29 11:42 被阅读0次

    前面的文章讲述了如何爬取到各种数据(例如:top10系列),如果这些数据能以标准API的方式共享出来,则大大提升数据使用的效率. 于是有了利用AWS EC2主机构建Web API的想法.

    步骤

    1. EC2 启动http service

    EC2默认没有安装http service. 首先利用'sudo yum install httpd'安装httpd, 再用'sudo service httpd restart' 启动http service. 如果你用的不是AMI image,安装方法会有差异,请自行Google确保http service启动成功.

    httpd

    2. httpd 安装mod_wsgi

    数据爬取用的是Python,服务器后端想到的自然是用Python写的flask framework (flask官网)

    连接httpd与flask的关键组件是mod_wsgi,同样AMI image默认没有安装,运行'sudo yum install mod_wsgi'安装.

    接下来是配置httpd.conf,编写app.wsgi文件,让三者连接起来正常运行.

    httpd.conf app.wsgi

    3. 创建flask application

    4. JSON data

    JSON已逐渐成为事实上的标准,flask framework也提供了API将各种Python数据结构转换成JSON format. 因此这些Web APIs提供JSON data

    5. 我的运行结果

    API Welcome page List all available funds List top10 funds List top10 funds by fund type

    6. Github地址

    https://github.com/stonkerlee/FundsRestApiProject

    相关文章

      网友评论

          本文标题:构建Web API

          本文链接:https://www.haomeiwen.com/subject/onwuvttx.html