[Ur] JSON web service/api?

Adam Chlipala adamc at csail.mit.edu
Wed Mar 8 14:19:13 EST 2017


On 03/08/2017 01:51 PM, Isaac Torbett wrote:
> I'm trying to get the urweb server to return json, but what is the 
> type/kind I should put in the transaction monad?
>
>
> val main : <here> -> transaction page
>
>
> What would I put in <here>?
>
> Furthermore- I don't even know if my json-like structure is allowed, 
> the compiler isn't complaining about it, so maybe it's fine.

I think Section 10 of the manual explains everything about how to write 
handlers that provide non-HTML-based APIs.  In short, you probably want 
to use argument type [postBody] or [queryString], depending on how the 
JSON comes in.  You can also use [returnBlob] to return JSON instead of 
HTML.

> fun main () = return queryX1 (SELECT topic.Title, topic.Body FROM topic)

It looks like you're hung up on the basics of programming with monads, 
for which I'd recommend a Haskell monad tutorial.  But the case-specific 
fix is to remove the [return].



More information about the Ur mailing list