on develop help sign in
Added a simple example of the general request flow.
f492849Tikhon Jelvis
src/Reflex/Dom/Xhr.hs+17
@@ -46,6 +46,23 @@ module Reflex.Dom.Xhr
46 --
46 --
47 -- 3. Consume the resulting stream of 'XhrResponse' events,
47 -- 3. Consume the resulting stream of 'XhrResponse' events,
48 -- parsing the body of the response however appropriate.
48 -- parsing the body of the response however appropriate.
49+ --
50+ -- Here is an example of calling a search API whenever the user
51+ -- types in a text input field and printing the result on the page:
52+ --
53+ -- @
54+ -- url query = "http://example.com/search?query=" <> query
55+ --
56+ -- search queries = do
57+ -- responses <- performRequestAsync $ toRequest <$> queries
58+ -- return $ view xhrResponse_responseText <$> responses
59+ -- where toRequest query = XhrRequest "GET" (url query) def
60+ --
61+ -- main = mainWidget $ do
62+ -- queries <- textInput def
63+ -- results <- search queries
64+ -- dynText $ holdDyn "No results." results
65+ -- @
49
66
50 -- ** XHR Requests
67 -- ** XHR Requests
51 , XhrRequest (..)
68 , XhrRequest (..)