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
2) Yes. Basically the compilation process is as follows:
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).
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):[<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).
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:
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
Regards,
z.
[<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.
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:
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.
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:
[<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.
Topic tags
- f# × 3663
- compiler × 263
- functional × 199
- websharper × 120
- c# × 119
- classes × 96
- web × 94
- book × 84
- .net × 82
- async × 72
- parallel × 43
- server × 43
- parsing × 41
- testing × 41
- asynchronous × 30
- monad × 28
- ocaml × 26
- tutorial × 26
- haskell × 25
- workflows × 22
- html × 21
- linq × 21
- introduction × 19
- silverlight × 19
- wpf × 19
- fpish × 18
- collections × 14
- pipeline × 14
- templates × 12
- monads × 11
- opinion × 10
- reactive × 10
- plugin × 9
- scheme × 9
- sitelets × 9
- solid × 9
- basics × 8
- concurrent × 8
- deployment × 8
- how-to × 8
- python × 8
- complexity × 7
- javascript × 6
- jquery × 6
- lisp × 6
- real-world × 6
- workshop × 6
- xaml × 6
- conference × 5
- dsl × 5
- java × 5
- metaprogramming × 5
- ml × 5
- scala × 5
- visual studio × 5
- formlets × 4
- fsi × 4
- lift × 4
- sql × 4
- teaching × 4
- alt.net × 3
- aml × 3
- enhancement × 3
- list × 3
- reflection × 3
- type provider × 3
- blog × 2
- compilation × 2
- computation expressions × 2
- corporate × 2
- courses × 2
- cufp × 2
- enterprise × 2
- entity framework × 2
- erlang × 2
- events × 2
- f# interactive × 2
- fsc × 2
- google maps × 2
- html5 × 2
- http × 2
- interactive × 2
- interface × 2
- iphone × 2
- iteratee × 2
- jobs × 2
- kendo × 2
- keynote × 2
- mvc × 2
- numeric × 2
- obfuscation × 2
- oop × 2
- packaging × 2
- pattern matching × 2
- pipelines × 2
- rx × 2
- script × 2
- seq × 2
- sockets × 2
- stm × 2
- tcp × 2
- trie × 2
- type × 2
- xna × 2
- zh × 2
- .net interop × 1
- 2012 × 1
- abstract class × 1
- accumulator × 1
- active pattern × 1
- addin × 1
- agents × 1
- agile × 1
- alter session × 1
- android × 1
- anonymous object × 1
- appcelerator × 1
- architecture × 1
- array × 1
- arrays × 1
- asp.net 4.5 × 1
- asp.net mvc × 1
- asp.net mvc 4 × 1
- asp.net web api × 1
- aspnet × 1
- ast × 1
- b-tree × 1
- bistro × 1
- bug × 1
- camtasia studio × 1
- canvas × 1
- class × 1
- client × 1
- clojure × 1
- closures × 1
- cloud × 1
- cms × 1
- coding diacritics × 1
- color highlighting × 1
- combinator × 1
- confirm × 1
- constructor × 1
- continuation-passing style × 1
- coords × 1
- coursera × 1
- csla × 1
- css × 1
- current_schema × 1
- data × 1
- database × 1
- declarative × 1
- delete × 1
- dhtmlx × 1
- discriminated union × 1
- distance × 1
- docs × 1
- documentation × 1
- dol × 1
- domain × 1
- du × 1
- duf-101 × 1
- eclipse × 1
- edsl × 1
- em algorithm × 1
- emacs × 1
- emotion × 1
- error × 1
- etw × 1
- euclidean × 1
- event × 1
- example × 1
- examples × 1
- ext js × 1
- extension methods × 1
- extra × 1
- facet pattern × 1
- fantomas × 1
- fear × 1
- float × 1
- fp × 1
- frank × 1
- fsdoc × 1
- fsharp.core × 1
- fsharp.powerpack × 1
- fsharpx × 1
- function × 1
- functional style × 1
- gc × 1
- generic × 1
- geometry × 1
- getlastwin32error × 1
- google × 1
- group × 1
- hash × 1
- history × 1
- hosting × 1
- httpcontext × 1
- https × 1
- hubfs × 1
- ie 8 × 1
- if-doc × 1
- inheritance × 1
- installer × 1
- interpreter × 1
- io × 1
- ios × 1
- ipad × 1
- kendochart × 1
- kendoui × 1
- learning × 1
- licensing × 1
- macro × 1
- macros × 1
- maps × 1
- markup × 1
- marshal × 1
- math × 1
- metro style × 1
- micro orm × 1
- minimum-requirements × 1
- multidimensional × 1
- multithreading × 1
- mysql × 1
- mysqlclient × 1
- nancy × 1
- nested × 1
- nested loops × 1
- node × 1
- object relation mapper × 1
- object-oriented × 1
- offline × 1
- option × 1
- orm × 1
- osx × 1
- owin × 1
- paper × 1
- parameter × 1
- performance × 1
- persistent data structure × 1
- phonegap × 1
- pola × 1
- powerpack × 1
- prefix tree × 1
- principle of least authority × 1
- programming × 1
- projekt_feladat × 1
- protected × 1
- provider × 1
- ptvs × 1
- quant × 1
- quotations × 1
- range × 1
- raphael × 1
- razor × 1
- rc × 1
- real-time × 1
- reference × 1
- restful × 1
- round table × 1
- runtime × 1
- scriptcs × 1
- scripting × 1
- service × 1
- session-state × 1
- sitelet × 1
- sqlentityconnection × 1
- stickynotes × 1
- stress × 1
- strong name × 1
- structures × 1
- tdd × 1
- template × 1
- tracing × 1
- tsunamiide × 1
- type inference × 1
- type providers × 1
- typescript × 1
- upload × 1
- vb × 1
- vb.net × 1
- vector × 1
- visual f# × 1
- visual studio 11 × 1
- visual studio 2012 × 1
- visual studio shell × 1
- visualstudio × 1
- web api × 1
- webapi × 1
- windows 7 × 1
- windows 8 × 1
- windows-phone × 1
- winrt × 1
- xml × 1
- zarovizsga × 1
|
Copyright (c) 2011-2012 IntelliFactory. All rights reserved. Home | Products | Consulting | Trainings | Blogs | Jobs | Contact Us |
Built with WebSharper |
I've been playing around with WebSharper for a couple of weeks now and am working on my first major sample. Hopefully, the FPish community can help me perform a sanity check to see if I'm making the following decisions for the right reasons:
(1) I decided to go with creating an offline HTML application (in the templates, it is "WebSharper 2.4 HTML Application (Sitelets)") because the website is hosted on a LAMP server and doesn't have the ability to host a DLL file or any server-side content. Any server-side functionality that the client needs is provided through an existing RESTful service. I was planning to use jQuery or some other asynchronous mechanism to retrieve/save data as needed. Is this the right decision? Should I create a "WebSharper 2.4 Web Application (Sitelets)"?
(2) When I created a couple of test offline applications, they started with sample code that includes server-side concepts. Upon compiling the application, it creates both a DLL and a HTML/JS-only set of files. Just running the HTML files off my local computer without a server seems to work. I integrated some of the Formlet examples from the manual and it looks like they are working correctly. I'm assuming that the DLL is used by WebSharper to translate some of the code from F# to JS, but I'm not sure. Is the DLL file just a by-product of the compilation process that I can ignore?
(3) When I integrated the Formlet examples into the applications, I ended up creating viewers similar to this:
However, the documentation for
IntelliFactory.WebSharper.Web.Controlsays that it is for creating server-side ASP.NET controls. Is this the correct way to do it or should I be doing something else?(4) From my limited understanding of .NET and WebSharper (this is the first time I've ever played with .NET, ASP or a windows-based server framework for web development), [<RPC>]-tagged sections of code should not exist in a client-only app. My mental picture of the whole RPC process is similar to how Google does it with GWT and GAE. I assume that all RPC-tagged sections are compiled to .NET code that runs on the server. Is this a correct assumption? Also, are there other parts of WebSharper that I should not use when writing a client-only application?
Those are just the questions I can think of at this time but if anyone has any advice on creating a client-only website that integrates with an existing network-based service, I would really appreciate your insights.
Thank you for your time and help,
z.
EDIT: I was able to answer question 3 myself after reading [link:groups.google.com] where Anton explains the bridging between server and client-side combinators. Apparently I did it correctly.