1) If all the server-side functionality is provided by a third party service, then yes, HTML Application is the good template to use.

For the interaction with RESTful services, jQuery is indeed a reasonable choice. A nice way to use it would be to create an asynchronous workflow using jQuery.ajax, something like the following (untested):

1
2
3
4
5
6
7
8
9
10
[<JavaScript>]
let asyncGet url : Async<'a> =
    Async.FromContinuations (fun (ok, err, _) ->
        let conf =
            JQuery.AjaxConfig(
                Url = url,
                Success = [| fun (res, _, _) -> ok (As<'a> res) |],
                Error = [| fun (_, msg, _) -> err (Failure msg) |]
            )
        JQuery.Ajax(conf) |> ignore)

2) Yes. Basically the compilation process is as follows:

  • Web Application (and WS Library) is a standard F# library project with an extra compilation step that generates the javascript files from the DLL.
  • HTML Application is like Web Application with a second extra step that generates the static HTML files.

So in the end, for HTML Application, all you need to deploy is the contents of the html directory; the rest can be ignored.

4) Correct again, RPC functions use the web server and cannot be used in a client-only app.

Basically, the only constraint of HTML Application is that everything that is not client-side is computed once during the extra compilation step I mentioned. Each Action is compiled into a static html page, so you are limited to a finite number of Actions (which you need to list in your Website.Actions).

By on 4/2/2012 5:11 AM ()

For anyone interested in this Ajax query, here is a version that works with RESTful web services that use JSON for the query / data format:

1
2
3
4
5
6
7
8
9
10
11
12
    [<JavaScript>]
    static member asyncGet url : Async<'a> =
      Async.FromContinuations
      <| fun (ok, _, _) ->
          let conf =
            JQuery.AjaxConfig(
              Url = url,
              Success = [| fun (res, msg, jqxhr) -> ok <| As<'a> (res, msg, jqxhr) |],
              DataType = (IntelliFactory.WebSharper.JQuery.DataType.Json :?> _)
            )
          JQuery.Ajax(conf)
          |> ignore

This is based directly on the documentation on jQuery's page. Adding a data parameter is easy as well. The added benefit is that the user has access to the result, the message from the server and the jqXHR object (if needed).

One interesting note is that it doesn't look like WebSharper can currently deal with System.Exception objects. I tried to modify and run the Error value in numerous ways, but it always resulted in either a compile-time or run-time error message.

Regards,

z.

By on 4/6/2012 11:13 PM ()

Hi Loic,

Thank you very much for your detailed reply. I'll continue on my path and see how it goes.

I'll test out the ajax inquiry you wrote as well. Having just a little experience with jQuery, I'm still trying to learn the intricacies of how to make it work for me. There is a similar query at [link:groups.google.com] but I haven't really tested that either.

Just for reference, here is what I wrote based on Vladimir Matveev's code:

1
2
3
4
5
6
7
8
9
    [<JavaScript>]
    static member GetJsonAsync(url : string, ?data : obj) = 
      Async.FromContinuations <|
        fun (ok, _, _) ->
          let cont (retData : obj, status : string) = ok (retData, status)
          match data with
          | Some d -> JQuery.GetJSON(url, d, cont)
          | None -> JQuery.GetJSON(url, cont)
          |> ignore

However, I think your query might provide a great deal more flexibility by modifying the individual .ajax() options. I'll try both to see if I can figure out which is better.

Regards,

zakaluka.

By on 4/2/2012 8:20 PM ()
IntelliFactory Offices Copyright (c) 2011-2012 IntelliFactory. All rights reserved.
Home | Products | Consulting | Trainings | Blogs | Jobs | Contact Us | Terms of Use | Privacy Policy | Cookie Policy
Built with WebSharper