sofa 的webhook实际上就是将graphql 的subscription 进行了扩展,当接受到sub 请求的时候
再做一次http 的转发处理,方便rest api 的访问

环境准备

环境还是使用的docker-compose ,以前的代码,只是添加了一个webhook 的容器镜像
可以参考: https://www.cnblogs.com/rongfengliang/p/10326302.html

  • docker-compose 文件
version: "3"
services:
api:
build: ./
image: dalongrong/sofa-graphql2rest
ports:
- "4000:4000"
webhook:
image: jeffail/benthos
volumes:
- "./configs/webhook.yaml:/benthos.yaml"
ports:
- "4195:4195"
  • webhook config
input:
type: broker
broker:
inputs:
- type: http_server
http_server:
path: /post/customer1
processors:
- type: text
text:
operator: prepend
value: "Customer 1 received: "
- type: http_server
http_server:
path: /post/customer2
processors:
- type: text
text:
operator: prepend
value: "Customer 2 received: "
- type: http_server
http_server:
path: /post/customer3
processors:
- type: text
text:
operator: prepend
value: "Customer 3 received: "
output:
type: stdout

启动&&测试

  • 启动
docker-compose up -d
  • 添加webhook
    请求的同时会启动webhook 的rest 请求
    请求的参数格式如下:
{
"subscription":"sub schema name ",
"variables":" some field just for filter data",
"url": "the webhook address"
}

使用curl 请求

curl -X POST \
http://localhost:4000/webhook \
-H 'Content-Type: application/json' \
-H 'Postman-Token: f2098fda-1108-4981-83b4-7eae3f3828c8' \
-H 'cache-control: no-cache' \
-d '{
"subscription":"onBook",
"url":"http://webhook:4195"
}'

返回数据
包含了webhook 的id

curl -X POST \
http://localhost:4000/webhook \
-H 'Content-Type: application/json' \
-H 'Postman-Token: f2098fda-1108-4981-83b4-7eae3f3828c8' \
-H 'cache-control: no-cache' \
-d '{
"subscription":"onBook",
"url":"http://webhook:4195"
}'
{"id":"2de735c3-5698-4cdd-9986-1941d1e20c88"}
  • 修改数据进行测试
    可以通过graphql 或者rest api

    webhook 数据
    docker-compose logs -f webhook
webhook_1 | get webhook message: {"data":{"onBook":{"id":"23337599919478412","title":"dalongdemo"}}}
  • webhook 订阅的删除以及修改
    删除操作
    DELETE /webhook/:id - 删除webhook
    POST /webhook/:id- 更新webhook

说明

sofa 的设计还是很不错的,给与我们一个反向的操作,一般我们的方式是rest2graphql ,但是这个是graphql2rest 同时提供了很不错的
功能支持

参考资料

https://github.com/Urigo/sofa
https://github.com/rongfengliang/sofa-graphql2rest-docker-compose

 
 
 
 

sofa graphql 2 rest api webhook 试用的更多相关文章

  1. sofa graphql 2 rest api 试用

      大部分代码还是来自sofa 的官方文档,同时添加了docker && docker-compose集成 备注: 代码使用typescript 同时运行的时候为了方便直接运行使用ts ...

  2. sofa graphql 2 rest api框架

    sofa 是一个出发点不一样的工具,提供了从graphql 2 rest 的处理,一般现有的框架都在 关注的是rest 2 graphql (大部分还是基于swagger.open api 标准进行设 ...

  3. 记一次通过c#运用GraphQL调用Github api

    阅读目录 GraphQL是什么 .net下如何运用GraphQL 运用GraphQL调用Github api 结语 一.Graphql是什么 最近在折腾使用Github api做个微信小程序练练手,本 ...

  4. 人人都是 API 设计师:我对 RESTful API、GraphQL、RPC API 的思考

    原文地址:梁桂钊的博客 博客地址:http://blog.720ui.com 欢迎关注公众号:「服务端思维」.一群同频者,一起成长,一起精进,打破认知的局限性. 有一段时间没怎么写文章了,今天提笔写一 ...

  5. Gravitee.io api gateway 试用

    以前写过几篇关于整体介绍的以及 使用docker 运行的简单说明,有了docker-compose 环境我们可以 方便的进行测试使用了. 环境准备 docker-compose 文件   versio ...

  6. sqler sql 转rest api javascript 试用

    sqler 内嵌了一个js 引擎的实现(基于goja,当我们配置了exec的配置之后 调用宏(redis 接口)或者rest api 的时候会有一个全局变量$result ,保存了执行的结果,我们可以 ...

  7. QLoo graphql engine 学习二 基本试用(kubernetes)

    已经测试过docker&& docker-compose 的运行模式,下面测试下kubernetes的运行模式 kubernetes 我使用docker for mac qloo 安装 ...

  8. QLoo graphql engine 学习一 基本试用(docker&&docker-compose)

      说明:使用docker-compose 进行安装 代码框架 使用命令行工具创建 qlooctl install docker qloo-docker 运行qloo&&gloo 启动 ...

  9. hasura graphql server event trigger 试用

    hasura graphql server 是一个很不错的graphql 引擎,当前版本已经支持event triiger 了 使用此功能我们可以方便的集成webhook功能,实现灵活,稳定,快捷的消 ...

随机推荐

  1. (C/C++学习笔记) 七. 类型转换

    七. 类型转换 ● 隐式类型转换 隐式类型转换 implicit type conversions #include<iostream> using namespace std; void ...

  2. Zabbix4.0监控URL

    一:新建群组 1.1:web monitor 二:新建模板 2.1:配置-模板-模板 2.3:创建应用集 配置-模板-web monitor-应用集 2.4:创建web场景 2.5:创建场景步骤: 以 ...

  3. js如何调试,使用debug模式

    js的代码断点调试非常简单,不需要借助代码编辑器,只要浏览器就行了(注意:html代码打断点是没有用的,只有js的才行,下图第二步打开开发者模式使用F12才对):

  4. L310

    Facelift( 紧肤术) followed by a week on a beach in Thailand? Hip surgery with a side of shopping inSing ...

  5. 解决jsp表达式不能解析的问题

    在jsp页面用了表达式,但是出现了表达式不能解析的问题 出现的页面如下 原因:web.xml的版本过低,maven自动生成的web.xml版本为2.3,只有2.3以上的版本才支持表达式 解决方法:改w ...

  6. random_select

    package sorttest;   //expected and worst running time is O(n),asuming that the elements are distinct ...

  7. LeetCode--122、167、169、189、217 Array(Easy)

    122. Best Time to Buy and Sell Stock II Say you have an array for which the ith element is the price ...

  8. Python基础4--一看就会的选择与循环

    1 选择 if elif else 注意后面均有: if age>18: print 'adult' elif age>6: print 'teenager' else: print 'k ...

  9. Diamorphine rootkit的使用

    仅作LKM rootkit研究之用,滥用后果自负. 查看支持版本是否为2.6.x/3.x/4.x: uname -r 下载代码: git clone https://github.com/m0nad/ ...

  10. linux 基础命令使用

    Centos中查看系统信息的常用命令 系统日志文件(可以通过cat或tail命令来查看) /var/log/message 系统启动后的信息和错误日志,是Red Hat Linux中最常用的日志之一  ...