anchor.diff:  -export([read_json/2]).
   -export([write_json/2]).
   
  --record(state, {path, hash}).
  +-record(state, {path, segments, hash}).
   
   init(_Transport, _Req, _Opts) ->
       {upgrade, protocol, cowboy_rest}.
  
positive.code: props_to_hprops(Props) ->
      lists:append([[Name, jiffy:encode(Value)] || {Name, Value} <- Props]).
  
  write_json(Req, #state{hash = undefined, path = Path} = State) ->
      {ok, Json, Req0} = cowboy_req:body(Req),
      {Props} = jiffy:decode(Json),
      Q = <<"insert into objects(hash,version,path,value) values (md5($1),0,''::hstore,hstore($2::text[]))">>,
      {ok, _} = cloudstore_pg:equery(cloudstore_pool, Q, [Path, props_to_hprops(Props)]),
      {true, Req0, State};
  write_json(Req, #state{hash = Hash} = State) ->
      {ok, Json, Req0} = cowboy_req:body(Req),
  
negative.code: 
  malformed_request(Req, State) ->
      {Path, Req0} = cowboy_req:path(Req),
      Segments = [list_to_binary(L)  || L <- string:tokens(binary_to_list(Path), "/")],
      {false, Req0, State#state{path = Path, segments = Segments}}.
  
  allowed_methods(Req, State) ->
      {[<<"GET">>, <<"PUT">>], Req, State}.
  