V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
爱意满满的作品展示区。
anson0370
V2EX  ›  分享创造

撸了一个用来快速构造一些 http api 的小东西,可能可以方便前端和客户端开发吧……

  •  
  •   anson0370 · 2014-12-04 11:33:23 +08:00 · 3134 次点击
    这是一个创建于 3432 天前的主题,其中的信息可能已经有所发展或是发生改变。
    https://github.com/anson0370/api_faker

    example:

    $ fakeApi api.js

    api.js:

    module.exports = {
    "[GET]/api/users": {
    name: "wtf"
    },
    "[GET]/api/user/:id": function(url, method, params) {
    return {
    id: params.id
    };
    }
    }

    use:

    $ curl -XGET http://127.0.0.1:8080/api/users
    {"name":"wtf"}

    $ curl -XGET http://127.0.0.1:8080/api/user/1
    {"id":"1"}

    非常简单的东西,其实对前后端一体的小伙伴们可能用处不大。总之撸都撸了,发给大家看看。
    6 条回复    2015-01-09 15:45:30 +08:00
    sarices
        1
    sarices  
       2014-12-04 11:42:09 +08:00   ❤️ 1
    一直用 restify
    RIcter
        2
    RIcter  
       2014-12-04 22:40:54 +08:00 via iPad
    记得淘宝内部就有一个类似于这个的东西
    oohusl
        3
    oohusl  
       2014-12-05 12:27:28 +08:00   ❤️ 1
    https://github.com/dreamhead/moco 这个应该很能满足这方面的需求
    anson0370
        4
    anson0370  
    OP
       2014-12-05 17:37:02 +08:00
    @sarices 其实用 node 或者 ruby 之类的撸几个 http api 是分分钟的事,就是省点模板代码,对于 java 之类的可能会比较麻烦一些。
    anson0370
        5
    anson0370  
    OP
       2014-12-05 17:41:15 +08:00
    @oohusl 粗略瞅了一眼,是挺接近的不过也复杂了不少。
    dallaslu
        6
    dallaslu  
       2015-01-09 15:45:30 +08:00
    我来学习一下「撸」字的新用法。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   925 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 22:34 · PVG 06:34 · LAX 15:34 · JFK 18:34
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.