zoukankan      html  css  js  c++  java
  • REST API

    postman搭建mock服务https://jingyan.baidu.com/article/63f23628422a300208ab3dac.html

    REST API

    实验目的

    1. 熟悉 REST API 的基本用法

    操作步骤

    (1) 命令行进入demos/rest-api-demo目录,执行下面的命令。

    $ npm install -S json-server

    (2) 在项目根目录下,新建一个 JSON 文件db.json

    {
      "posts": [
        { "id": 1, "title": "json-server", "author": "typicode" }
      ],
      "comments": [
        { "id": 1, "body": "some comment", "postId": 1 }
      ],
      "profile": { "name": "typicode" }
    }

    (3) 打开package.json,在scripts字段添加一行。

    "scripts": {
      "server": "json-server db.json",
      "test": "..."
    },

    (4) 命令行下执行下面的命令,启动服务。

    $ npm run server

    (5)打开 Chrome 浏览器的 Postman 应用。依次向http://127.0.0.1:3000/postshttp://127.0.0.1:3000/posts/1发出GET请求,查看结果。

    (6)向http://127.0.0.1:3000/comments发出POST请求。注意,数据体Body要选择x-www-form-urlencoded编码,然后依次添加下面两个字段。

    body: "hello world"
    postId: 1

    发出该请求后,再向http://127.0.0.1:3000/comments发出GET请求,查看结果。

    (7) 向http://127.0.0.1:3000/comments/2发出PUT请求,数据体Body要选择x-www-form-urlencoded编码,然后添加下面的字段。

    body: "hello react"

    发出该请求后,再向http://127.0.0.1:3000/comments发出GET请求,查看结果。

    (8)向http://127.0.0.1:3000/comments/2发出delete请求。

    发出该请求后,再向http://127.0.0.1:3000/comments发出GET请求,查看结果。

  • 相关阅读:
    HDU 2822 Dogs【两次bfs】
    HDU 2819 Swap【二分图|启发题】
    HDU 2818 Building Block【并查集+根节点偏移量】
    HDU 2817 A sequence of numbers【水题|快速幂】
    Linux内核分析--操作系统是如何工作的
    讲座感想
    用eclipse开发和调试postgresql-8.4.1
    Ubuntu 14.04下翻译软件的安装与比较
    Linux下autoconf和automake使用
    github 使用网址
  • 原文地址:https://www.cnblogs.com/huyanluanyu/p/10179961.html
Copyright © 2011-2022 走看看