zoukankan      html  css  js  c++  java
  • 本地搭建接口 jsonserver

    1、终端跟路径安装json-sever      命令:npm install -g json-server  (windows)

             命令:sudo npm install -g json-server  (mac)

    2、创建 jsonserver  文件夹 

      2.1 初始化文件  命令:npm  init   

      2.2   初始化后  在 jsonserver  文件夹里多了个package.json  文件

    3、当前文件(jsonserver文件夹)加下安装  json-server   命令:sudo npm install json-server --save    安装完后package.json里多了   

    "dependencies": {
    "json-server": "^0.14.0"
    }

    4.   修改  package.json  文件的script   部分   :

    "scripts": {
    "json:server": "json-server --watch db.json",
    "json:server:remote":"json-server http://jsonplaceholder.typicode.com/db"
    },

    5、在jsonser文件夹下创建db.json 文件:

      在里面创建数据例如:

    {
    "users": [
    {
    "name": "Henry",
    "phone": "333-444-555",
    "email": "henry@gmail.com",
    "education": "adsfasfd",
    "graduationschool": "asdfasfd",
    "profession": "asdfasdf",
    "profile": "asdfasfdasdf",
    "id": 1
    },
    {
    "name": "adfasdf",
    "phone": "fasdfasfd",
    "email": "asdfasfd",
    "education": "fasdfasfd",
    "graduationschool": "fasfasdf",
    "profession": "sdfasdfafd",
    "profile": "asdfasdf",
    "id": 3
    },
    {
    "name": "米斯特吴",
    "phone": "13651322451",
    "email": "27732357@qq.com",
    "education": "本科",
    "graduationschool": "北京语言大学",
    "profession": "前端开发工程师",
    "profile": "大家好!",
    "id": 4
    },
    {
    "name": "asdfasfd",
    "phone": "asfasf",
    "email": "asdfasfd",
    "id": 5
    }
    ],
    "companies": [
    {
    "id": 1,
    "name": "Apple",
    "description": "Apple is good!"
    },
    {
    "id": 2,
    "name": "Microsoft",
    "description": "Microsoft is good!"
    },
    {
    "id": 3,
    "name": "Google",
    "description": "Google is good!"
    }
    ]
    }

    6、  运行 命令:npm run json:server  

    npm run json:server:remota

    结果 :运行成功

     {^_^}/ hi!

     

      Loading db.json

      Done

     

      Resources

      http://localhost:3000/users

      http://localhost:3000/companies

     

      Home

      http://localhost:3000

     

    7、在浏览器中运行查看把

  • 相关阅读:
    解剖Nginx·自动脚本篇(7)类型相关脚本系列
    解剖Nginx·自动脚本篇(6)编译器名称变量脚本 auto/cc/name
    解剖Nginx·自动脚本篇(5)编译器相关主脚本
    解剖Nginx·自动脚本篇(4)工具型脚本系列
    解剖Nginx·自动脚本篇(3)源码相关变量脚本 auto/sources
    解剖Nginx·自动脚本篇(2)设置初始变量脚本 auto/init
    解剖Nginx·自动脚本篇(1)解析配置选项脚本 auto/options
    解剖Nginx·模块开发篇(5)解读内置非默认模块 ngx_http_stub_status_module
    jupyter nb + scite 混合搭建成我的最爱IDE
    md语法之行内代码和代码片续集
  • 原文地址:https://www.cnblogs.com/jinsuo/p/9244966.html
Copyright © 2011-2022 走看看