流cURL响应到另一个发布结果的cURL命令 [英] Stream cURL response to another cURL command posting the result
问题描述
有一个公开的流媒体Meetup API,用于流JSON事件: http://stream.meetup.com/ 2 / rsvps
There's a public streaming Meetup API that streams JSON events: http://stream.meetup.com/2/rsvps
在命令行的一行中,我希望能够重定向该流,以便将每个JSON对象发布到另一个API。
In a single line from the command line, I'd like to be able to redirect that stream such that each JSON object is POSTed to another API.
我已经尝试了很多cURL的排列,但到目前为止还无法使其正常工作。我当前的尝试类似于:
I've tried lots of permutations of cURL but thus far have been unable to make it work. My current attempt looks something like:
curl -s http://stream.meetup.com/2/rsvps | curl -H "Content-Type: application/json" -X POST -d @- 'http://my-api-url-here'
据我所知,这什么也没有产生。请求不会流式传输到目标API,并且没有任何内容发送到标准输出。另外,我希望看到标准输出,但核心要求是将JSON记录流式传输到目标API。
This produces nothing as far as I can see. The requests are not streamed to the destination API and nothing is sent to standard out. As a bonus, I'd like to see the standard output but the core requirement is streaming the JSON records to the target API.
如果我尝试将流重定向到a像这样的文件:
If I try redirecting the stream to a file like:
curl -s http://stream.meetup.com/2/rsvps > output.txt
这可以按预期工作。挑战似乎是将初始cURL流的输出作为数据传递到POST。
This works as expected. The challenge seems to be getting the output from the initial cURL stream to POST as data to the second.
推荐答案
假设,一次10个事件
curl -H Content-Type:application / json -X POST -d [$( curl -s http://stream.meetup.com/2/rsvps | sed -n'1 {p;:loop n; p; 10q; b loop}'| sed -re'1,9 s / [}] $ /},/')]'http:// my-api-url-here'
如会议文档,可以使用since_count和since_mtime限制事件的数量。
As suggested by meetup docs, the number of events may be limited using since_count and since_mtime.
这篇关于流cURL响应到另一个发布结果的cURL命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!