Search code examples
jsonhttp-postlazarusapp-inventorapache-synapse

How to store a value in a TinyWebDB using Synapse?


I'm trying to store a value in a TinyWebDB component (AppInventor) by using the Synapse library. I managed to get a value using this code:

    procedure GetValue(Tag:String);
    var URL: string;
        Params: string;
        Response: TMemoryStream;

    begin
      Response := TMemoryStream.Create;

      try
        URL := 'http://appinvtinywebdb.appspot.com/getvalue';

        Params := 'tag=' + EncodeURLElement(Tag);

        if HttpPostURL(URL, Params, Response) then
          Response.SaveToFile('response.txt');

      finally
        Response.Free;
      end;
    end;

But I can't store a value. Any ideas or suggestions? By the way I tried to store a value by adding another parameter and formatting the code like this:

procedure StoreValue(Tag, Value: String);
var URL: string;
    Params: string;
    Response: TMemoryStream;

begin
  Response := TMemoryStream.Create;

  try
    URL := 'http://appinvtinywebdb.appspot.com/storevalue';

    Params := 'tag=' + EncodeURLElement(Tag)+'&'+
              'value='+ EncodeURLElement(Value);

    if HttpPostURL(URL, Params, Response) then
      Response.SaveToFile('response.txt');

  finally
    Response.Free;
  end;
end;

It doesn't seem to be working, because the response file is empty. It should contain something like this:

["STORED", "SomeTag", "SomeValue"]


Solution

  • I figured it out. The second piece of code is working, except for the URL. The URL I used was

    http://appinvtinywebdb.appspot.com/storevalue

    instead of

    http://appinvtinywebdb.appspot.com/storeavalue

    Conclusion: the code works perfectly, the result is ["STORED", "SomeTag", "SomeValue"].