[Ur] Serving Non-XML Text?

Evan Danaher ur at edanaher.net
Sat Jan 26 00:21:07 EST 2013


On Sat, Jan 26, 2013 at 04:58:13PM +1300, Chris Double wrote:
> On Sat, Jan 26, 2013 at 12:30 PM, Evan Danaher <ur at edanaher.net> wrote:
> > Unfortunately, AFAICT, public functions returning "transaction page",
> > and only such functions, are exposed as routes.  So I have to return
> > JSON wrapped in XML, which is pretty ugly (and breaks compatibility with
> > what I've got).  It wouldn't be too hard to add a thin proxy to strip
> > this out, but I thought I'd check first if there's any support in Ur/Web
> > for serving non-XML pages.
> 
> You can serve JSON with code like:
> 
> fun rate () =
>   let
>     val mimetype : mimeType = blessMime "text/plain"
>     val json = "...json string here..."
>   in
>     returnBlob (textBlob json) mimetype
>   end
> 
> You can build json from the result of queries with List.mapQuery to
> get a list of results then form a JSON string from it.

Thanks!  returnBlob and mimeType were the hooks I needed; somehow, in my
multiple reads through the reference manual, I missed that segment.
With a bit more poking (mostly around the "allow mime" directive),
things are working wonderfully now.

> -- 
> http://www.bluishcoder.co.nz
> 
> _______________________________________________
> Ur mailing list
> Ur at impredicative.com
> http://www.impredicative.com/cgi-bin/mailman/listinfo/ur
> 



More information about the Ur mailing list