CouchDB 映射函数中的 GET 请求
GET requests in CouchDB map function
是否可以在视图的地图功能中使用 GET 请求向外部 Web 服务发出 GET 请求?例如。我有一个带有 REST API 的分类服务。我想通过调用(非异步)API 函数对 map 函数中的文档进行分类。是否可以在 JavaScript 中实施?
不适用于默认的 javascript 查询服务器。但是,如果启用 native erlang query server,则可以执行任意代码,包括发出 http 请求。例如你可以这样做
%% Map Function
fun({Doc}) ->
<<K,_/binary>> = proplists:get_value(<<"_rev">>, Doc, null),
V = proplists:get_value(<<"_id">>, Doc, null),
%% Making the http request
{ok,{Status,Headers,Body}} = httpc:request("some url"),
%% do some stuff with the response and then emit
Emit(<<K>>, V)
end.
是否可以在视图的地图功能中使用 GET 请求向外部 Web 服务发出 GET 请求?例如。我有一个带有 REST API 的分类服务。我想通过调用(非异步)API 函数对 map 函数中的文档进行分类。是否可以在 JavaScript 中实施?
不适用于默认的 javascript 查询服务器。但是,如果启用 native erlang query server,则可以执行任意代码,包括发出 http 请求。例如你可以这样做
%% Map Function
fun({Doc}) ->
<<K,_/binary>> = proplists:get_value(<<"_rev">>, Doc, null),
V = proplists:get_value(<<"_id">>, Doc, null),
%% Making the http request
{ok,{Status,Headers,Body}} = httpc:request("some url"),
%% do some stuff with the response and then emit
Emit(<<K>>, V)
end.