V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
xiaojieluo
V2EX  ›  程序员

没事撸了个 api 的快速开发模板

  •  
  •   xiaojieluo · 2017-03-24 08:09:53 +08:00 · 1873 次点击
    这是一个创建于 2589 天前的主题,其中的信息可能已经有所发展或是发生改变。

    连框架都算不上,就一个简单的目录结构,编程语言使用的是 python, 服务器用了 tornado, api 返回格式是 json

    Github 地址: https://github.com/xiaojieluo/api_template

    求 star...

    安装

    git clone https://github.com/xiaojieluo/api_template.git
    pip install -r requirements.txt
    python main.py
    

    使用

    默认端口是 8888 浏览器直接打开 localhost:8888/

    tigerstudent
        1
    tigerstudent  
       2017-03-24 09:02:55 +08:00
    我的天
    renyijiu
        2
    renyijiu  
       2017-03-24 09:26:06 +08:00
    ```python
    #!/usr/bin/env python
    # codin=utf-8
    ```

    main.py 里这个没写错?
    LeoQ
        3
    LeoQ  
       2017-03-24 09:44:05 +08:00 via iPhone
    @renyijiu 同意, python3 里已经不需要定义字符编码了
    Kilerd
        4
    Kilerd  
       2017-03-24 09:57:21 +08:00
    不明其所述
    mkstring
        5
    mkstring  
       2017-03-24 10:42:09 +08:00
    好厉害哦!
    KIDJourney
        6
    KIDJourney  
       2017-03-24 10:49:15 +08:00
    #!/usr/bin/env python
    # coding=utf-8

    from api.handler.APIHandler import APIHandler

    class index(APIHandler):
    def get(self, username):
    data = {
    "name":username
    }
    self.write_json(data)


    你在逗我?这算什么模板。
    xiaojieluo
        7
    xiaojieluo  
    OP
       2017-03-24 13:56:37 +08:00
    @renyijiu 写快了漏掉了...
    xiaojieluo
        8
    xiaojieluo  
    OP
       2017-03-24 13:57:33 +08:00
    @KIDJourney 这只是组织了一下目录结构啊,小玩意
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2922 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 15:19 · PVG 23:19 · LAX 08:19 · JFK 11:19
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.