From f2275fd25463764ea059b32ffb689baeeebc1ca1 Mon Sep 17 00:00:00 2001 From: "Damien F. Katz" Date: Fri, 8 Aug 2008 21:06:29 +0000 Subject: Idempotent document creation support, new HTTP api to generate UUIDs and support in the couch.js library for using them. Creating uuids client side ensure that document creation happens only once, despite automatic network retries. git-svn-id: https://svn.apache.org/repos/asf/incubator/couchdb/trunk@684092 13f79535-47bb-0310-9956-ffa450edef68 --- src/couchdb/couch_httpd.erl | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'src') diff --git a/src/couchdb/couch_httpd.erl b/src/couchdb/couch_httpd.erl index 85fbe868..7b926019 100644 --- a/src/couchdb/couch_httpd.erl +++ b/src/couchdb/couch_httpd.erl @@ -97,6 +97,8 @@ handle_request0(Req, DocumentRoot, Method, Path) -> handle_replicate_request(Req, Method); "/_restart" -> handle_restart_request(Req, Method); + "/_uuids" -> + handle_uuids_request(Req, Method); "/_utils" -> {ok, Req:respond({301, [ {"Location", "/_utils/"} @@ -148,6 +150,17 @@ handle_restart_request(Req, 'POST') -> handle_restart_request(_Req, _Method) -> throw({method_not_allowed, "POST"}). +handle_uuids_request(Req, 'POST') -> + Count = list_to_integer(proplists:get_value("count", Req:parse_qs(), "1")), + % generate the uuids + UUIDs = [ couch_util:new_uuid() || _ <- lists:seq(1,Count)], + % send a JSON response + send_json(Req, {obj, [{"uuids", list_to_tuple(UUIDs)}]}); + +handle_uuids_request(_Req, _Method) -> + throw({method_not_allowed, "POST"}). + + % Database request handlers handle_db_request(Req, Method, {Path}) -> -- cgit v1.2.3