使用nodered实现httpclient和httpserver

http应用非常简单,无非客户端请求和服务端提供服务,先上一个效果图,请求服务和提供服务:
httpdemoresult

客户端请求服务

  • 创建流程
    示例采用三个节点,注入、http request、debug
[
    {
        "id": "cc288cf7.d2442",
        "type": "inject",
        "z": "c7956a02.c84278",
        "name": "",
        "topic": "",
        "payload": "",
        "payloadType": "date",
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "x": 110,
        "y": 100,
        "wires": [
            [
                "947677aa.2f92c8"
            ]
        ]
    },
    {
        "id": "947677aa.2f92c8",
        "type": "http request",
        "z": "c7956a02.c84278",
        "name": "",
        "method": "GET",
        "ret": "txt",
        "paytoqs": false,
        "url": "http://localhost:8001/students/1",
        "tls": "",
        "persist": false,
        "proxy": "",
        "authType": "",
        "x": 300,
        "y": 100,
        "wires": [
            [
                "b6fa8b31.a0f9a8"
            ]
        ]
    },
    {
        "id": "b6fa8b31.a0f9a8",
        "type": "debug",
        "z": "c7956a02.c84278",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "x": 500,
        "y": 100,
        "wires": []
    }
]

服务端提供服务

  • 创建流程
    示例采用三个节点,http in、http request、http response
[
    {
        "id": "d4450f50.c8d0e",
        "type": "http in",
        "z": "c7956a02.c84278",
        "name": "",
        "url": "/nhs",
        "method": "get",
        "upload": false,
        "swaggerDoc": "",
        "x": 100,
        "y": 220,
        "wires": [
            [
                "d2a5e002.21a2b"
            ]
        ]
    },
    {
        "id": "dc29f6d5.3fc0e8",
        "type": "http response",
        "z": "c7956a02.c84278",
        "name": "",
        "statusCode": "",
        "headers": {},
        "x": 530,
        "y": 220,
        "wires": []
    },
    {
        "id": "d2a5e002.21a2b",
        "type": "http request",
        "z": "c7956a02.c84278",
        "name": "",
        "method": "GET",
        "ret": "txt",
        "paytoqs": false,
        "url": "http://localhost:8001/students/1",
        "tls": "",
        "persist": false,
        "proxy": "",
        "authType": "",
        "x": 300,
        "y": 240,
        "wires": [
            [
                "dc29f6d5.3fc0e8"
            ]
        ]
    }
]

json-server

示例中http://localhost:8001/students/1是使用json-server搭建的一个本地测试服务
jsonserver

欢迎来访

  • 有问题欢迎留言或加交流qq:825121848
  • 转载请注明出处
  • 请小编喝茶~