• [Node.js] Creating Demo APIs with json-server


    json-server makes it extremely easy to setup robust JSON apis to use for demos and proof of concepts. John walks you through the process of using pre-built json files for a server and how to generate larger datasets using lodash and faker.

    Install:

    npm install -g json-server
    

    Create a json file:

    {
        "people": [
            {
                "id": 0,
                "name": "John"
            }
        ]
    }

    Run:

    json-server db.json

    It will run the localhost:3000:

    It return the data:

    [{"id":0,"name":"John"}]

    or db:

    {"people":[{"id":0,"name":"John"}]}

    You also can do POST; DELETE; GET;

    For example POST:

    After I post twice, we got three results:

    [{"id":0,"name":"John"},{"name":"Yuri","id":1},{"name":"Yuri","id":2}]

    We can UPDATE the last one also:

    Get more data to play with:

    /**
     * Created by Answer1215 on 1/13/2015.
     */
    module.exports = function() {
        var faker = require('faker');
        var _ = require('lodash');
    
        return {
            people: _.times(100, function(n) {
                return{
                    id: n,
                    name: faker.name.findName(),
                    avater: faker.internet.avatar()
                }
            })
        }
    }

    Query

  • 相关阅读:
    oracle-Oracle试题
    webservice-WebService试题
    php-PHP试题
    xml-xml试题
    ajax-Ajax试题
    用java在客户端读取mongodb中的数据并发送至服务器
    表格标记
    HTML常用标记
    Java操作Mongodb 保存/读取java对象到/从mongodb
    Spark Streaming的编程模型
  • 原文地址:https://www.cnblogs.com/Answer1215/p/4220137.html
Copyright © 2020-2023  润新知