[Ur] Handling POST requests that aren't from forms

Adam Chlipala adamc at impredicative.com
Wed Dec 15 08:48:27 EST 2010


Chris Double wrote:
> I want to use an external service that regularly sends a POST request
> to my Ur/Web application containing text data as the body of the POST.
> I tried something like the following to log to a file:
>
> fun notifyMessage body =
>    dml (INSERT INTO messages (Message) VALUES ({[body]}));
>    return<xml>0</xml>
>
> Where 'messages' is a table containing the string that is the message.
> This won't build in Ur/Web because 'notifyMessage' has as side effect
> and Ur/Web is telling me to use it in a form. But the function isn't
> actually used anywhere in my application itself - it's POSTed to
> directly from an other service.
>
> How can I write something in Ur/Web to handle this POST?
>    

This is one of the ugly parts of the current implementation, but there 
_is_ a fairly simple workaround pattern that I've employed.

Step 1: In another function (its name doesn't matter, since you won't 
expect anyone to access its page), create a dummy form that submits to 
[notifyMessage].
Step 2: In the signature of this module (i.e., the .urs file), include 
the dummy function but not [notifyMessage].

There may be a good way of supporting externally-callable forms without 
this sort of acrobatics, but, for now, this method isn't so bad.



More information about the Ur mailing list