% The module should have the same name as the file -module(couch_httpd_numidx). -export([handle_numidx_req/3]). -include("couch_db.hrl"). -import(couch_httpd, [send_json/2, send_method_not_allowed/2]). % path_parts is the url, split at the slashes handle_numidx_req(#httpd{method='GET', path_parts=[DbName, <<"_design">>, DName, <<"_numidx">>, JsonRange] }=Req, Db, _DDoc) -> % Parse range parameter Range = list_to_tuple(?JSON_DECODE(JsonRange)), % Build the numidx data structure from the database ok = couch_numidx:get_docs(Db), % Perform the range search Result = couch_numidx:range_search(Range), % CouchDB normally returns JSON, so do we send_json(Req, {[ {<<"db">>, DbName}, {<<"designdoc">>, DName}, {<<"result">>, Result} ]}); % We allow only GET and HEAD requests handle_numidx_req(Req, _, _) -> send_method_not_allowed(Req, "GET,HEAD").