V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
爱意满满的作品展示区。
anson0370

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

  •  
  •   anson0370 · Dec 4, 2014 · 4118 views
    This topic created in 4168 days ago, the information mentioned may be changed or developed.
    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 replies    2015-01-09 15:45:30 +08:00
    sarices
        1
    sarices  
       Dec 4, 2014   ❤️ 1
    一直用 restify
    RIcter
        2
    RIcter  
       Dec 4, 2014 via iPad
    记得淘宝内部就有一个类似于这个的东西
    oohusl
        3
    oohusl  
       Dec 5, 2014   ❤️ 1
    https://github.com/dreamhead/moco 这个应该很能满足这方面的需求
    anson0370
        4
    anson0370  
    OP
       Dec 5, 2014
    @sarices 其实用 node 或者 ruby 之类的撸几个 http api 是分分钟的事,就是省点模板代码,对于 java 之类的可能会比较麻烦一些。
    anson0370
        5
    anson0370  
    OP
       Dec 5, 2014
    @oohusl 粗略瞅了一眼,是挺接近的不过也复杂了不少。
    dallaslu
        6
    dallaslu  
       Jan 9, 2015
    我来学习一下「撸」字的新用法。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2386 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 37ms · UTC 10:23 · PVG 18:23 · LAX 03:23 · JFK 06:23
    ♥ Do have faith in what you're doing.