<turbo-stream action="append" target="posts_list"><template>    <div class="postbit" id="33583" data-post-id="33583">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="peerreynders" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/peerreynders/120/5826_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  peerreynders
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<aside class="quote no-group" data-username="OvermindDL1" data-post="21" data-topic="5145">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/overminddl1/48/2677_2.png" class="avatar"> OvermindDL1:</div>
<blockquote>
<p>GraphQL is just a query, think SQL, but for JSON, still very succinct and simple,</p>
</blockquote>
</aside>
<p>This is where I see the biggest danger with GraphQL - people deciding to simply pull an <a href="http://docs.servicestack.net/why-not-odata" rel="noopener nofollow ugc">OData</a> and expose the persistence schema all the way up to the front end, creating a franken-system, architectural and maintenance nightmare where the frontend is deeply coupled into every little aspect of the persistence layer.</p>
<p>GraphQL can be a big plus provided its schema is designed around <a href="https://martinfowler.com/articles/consumerDrivenContracts.html" rel="noopener nofollow ugc">consumer-driven contracts</a> but I imagine quite often that is seen as just too much effort - and ultimately laziness will drive people to head for the next button that promises to generate a GraphQL application to expose the database as is.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="33583" data-batch-url="/posts/batch_likers">
                        0
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/help-making-a-design-choice-ajax-vs-websocket/5145/22">Post #21</a>
	                </div>
	            </div>
              <div id="likers-container-33583" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="33583"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #21"></div>
  </section>
</div>
    <div class="postbit" id="33584" data-post-id="33584">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="OvermindDL1" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/OvermindDL1/120/2677_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  OvermindDL1
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<aside class="quote no-group" data-username="peerreynders" data-post="22" data-topic="5145">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/peerreynders/48/5826_2.png" class="avatar"> peerreynders:</div>
<blockquote>
<p>This is where I see the biggest danger with GraphQL - people deciding to simply pull an OData and expose the persistence schema all the way up to the front end, creating a franken-system, architectural and maintenance nightmare where the frontend is deeply coupled into every little aspect of the persistence layer.</p>
<p>GraphQL can be a big plus provided its schema is designed around consumer-driven contracts but I imagine quite often that is seen as just too much effort - and ultimately laziness will drive people to head for the next button that promises to generate a GraphQL application to expose the database as is.</p>
</blockquote>
</aside>
<p>This is what so many do with REST yeah…</p>
<p>It really should <em>not</em> be done with GraphQL, it is more of RPC, a function call to acquire data and get a response back, except of course you can state in what format you want the data back in.  I just add a new absinthe schema/object when I need to call a new ‘function’ to get some data that I’ve not needed yet.  Two of them do not even access the database at all.  ^.^</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="33584" data-batch-url="/posts/batch_likers">
                        0
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/help-making-a-design-choice-ajax-vs-websocket/5145/23">Post #22</a>
	                </div>
	            </div>
              <div id="likers-container-33584" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="33584"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #22"></div>
  </section>
</div>
    <div class="postbit" id="33593" data-post-id="33593">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="Emily" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/Emily/120/2422_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  Emily
                    <span class="op-star" title="Thread Starter">
                      <img alt="OP" class="op-star-icon" src="/assets/thread-icons/thread-icon-thread-starter-df91e872.png" />
                    </span>
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>…Always enlightening to watch the discussions unfold here.</p>
<p>I’m going to have to make some key decisions on an API architecture soon.  This discussion has open up a lot of thought threads I didn’t have before <img src="https://forum.elixirforum.com/images/emoji/apple/slight_smile.png?v=15" title=":slight_smile:" class="emoji" alt=":slight_smile:" loading="lazy" width="20" height="20"></p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="33593" data-batch-url="/posts/batch_likers">
                        0
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/help-making-a-design-choice-ajax-vs-websocket/5145/24">Post #23</a>
	                </div>
	            </div>
              <div id="likers-container-33593" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="33593"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #23"></div>
  </section>
</div>
    <div class="postbit" id="33609" data-post-id="33609">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="rubencaro" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/rubencaro/120/1841_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  rubencaro
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Before this cools down, I would like to add http2 to the mix. Cowboy will soon support it, all major browsers do, and many server technologies already support it by default.</p>
<p>Doesn’t that make the pair SSE+AJAX a simpler option to solve this?</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="33609" data-batch-url="/posts/batch_likers">
                        0
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/help-making-a-design-choice-ajax-vs-websocket/5145/25">Post #24</a>
	                </div>
	            </div>
              <div id="likers-container-33609" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="33609"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #24"></div>
  </section>
</div>
    <div class="postbit" id="33622" data-post-id="33622">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="peerreynders" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/peerreynders/120/5826_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  peerreynders
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<aside class="quote no-group" data-username="rubencaro" data-post="25" data-topic="5145">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/rubencaro/48/1841_2.png" class="avatar"> rubencaro:</div>
<blockquote>
<p>Doesn’t that make the pair SSE+AJAX a simpler option to solve this?</p>
</blockquote>
</aside>
<p>As usual I think “it depends”. I would think SSE + AJAX would scale better in a situation where the infrastructure implements HTTP caching <strong>and</strong> applications are designed to prefer cacheable non-client specific responses - but there are a lot of “fiddly bits” you have to pay attention to and get right <strong>and</strong> you have to have the volume of traffic to make it all worthwhile. I think many will forego the potential cacheability of HTTP responses and go straight for web sockets so they can just stay inside “one single communication concept”.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="33622" data-batch-url="/posts/batch_likers">
                        1
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/help-making-a-design-choice-ajax-vs-websocket/5145/26">Post #25</a>
	                </div>
	            </div>
              <div id="likers-container-33622" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="33622"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #25"></div>
  </section>
</div>
    <div class="postbit" id="33625" data-post-id="33625">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="rubencaro" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/rubencaro/120/1841_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  rubencaro
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Imagine you cannot take advantage of cache mechanisms (that <em>may</em> match AJAX better).</p>
<p>Just the case of clients sending plain JSON messages and servers responding JSON messages, just like you would do with Websockets.</p>
<p>If you take into account http2, AJAX requests have no connection overhead and are simple standard fetch requests, SSE is a plain oneliner with no dependencies, so I guess you get bidirectional comms plain&amp;simple.</p>
<p>Then you can use this from vanilla js, from Vuejs, or from wherever you want. No further abstractions or 3rd party dependencies needed.</p>
<p>You can elaborate on top of that of course, but what I am asking is about the base bidirectional mechanism. On this scenario, what are the cases where we should prefer Websockets over SSE+AJAX?</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="33625" data-batch-url="/posts/batch_likers">
                        0
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/help-making-a-design-choice-ajax-vs-websocket/5145/27">Post #26</a>
	                </div>
	            </div>
              <div id="likers-container-33625" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="33625"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #26"></div>
  </section>
</div>
    <div class="postbit" id="33687" data-post-id="33687">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="Azolo" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/Azolo/120/2189_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  Azolo
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>There’s a good information on this thread but I think it speaks past the underlying question, “Should I learn WebSockets or AJAX.” So instead of trying to add more information to what has been said, I’m just going to share my experience based off the original question.</p>
<p>The TL;DR version is:</p>
<p>If you are just making requests or just learning then learn “AJAX”. It’s basically the difference between using a generalized tool and a specialized tool. When you need WebSockets you will know it. But I would never use WebSockets exclusively in my applications without a very good reason.</p>
<p>The long reason is:</p>
<aside class="quote no-group" data-username="Emily" data-post="1" data-topic="5145">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/emily/48/2422_2.png" class="avatar"> Emily:</div>
<blockquote>
<p>I need to setup communication between VueJS &amp; Elixir Modules.  I’m told my options are AJAX &amp; Websocket.</p>
</blockquote>
</aside>
<p>This is like saying, “Your options are http requests or a persistent connection.” It’s really just a way of retrieving data and the simpler solution is probably http requests. The main instance where WebSockets are better is when you need to push realtime data to the client.</p>
<aside class="quote no-group" data-username="Emily" data-post="1" data-topic="5145">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/emily/48/2422_2.png" class="avatar"> Emily:</div>
<blockquote>
<p>Primary consideration is latency.</p>
</blockquote>
</aside>
<p>This is really on you. Most of the latency will be at the processing level not the connection level.</p>
<p>Unless you’re going to be passing massive amounts of information at once. In that case, your underlying WebSocket implementation would have to support compression to be faster.</p>
<aside class="quote no-group" data-username="Emily" data-post="1" data-topic="5145">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/emily/48/2422_2.png" class="avatar"> Emily:</div>
<blockquote>
<p>Second consideration is learning time &amp; code complexity.</p>
</blockquote>
</aside>
<p>This is a hard one for me to answer. I don’t think either are particularly hard to learn and Phoenix will take out a lot of the pain in WebSockets. However, you will have to use the bundled Phoenix JavaScript libraries.</p>
<p>As long as you can abstract the data layer in your Vue.js application then it really won’t matter that much anyway.</p>
<aside class="quote no-group" data-username="Emily" data-post="1" data-topic="5145">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/emily/48/2422_2.png" class="avatar"> Emily:</div>
<blockquote>
<p>Third consideration is documentation &amp; available tutorials/learning resources (as I’ll be teaching myself).</p>
</blockquote>
</aside>
<p>HTTP requests, hands down. But I imagine that it doesn’t matter much actually. Since either of the methods are just about updating the underlying data. Depending on your level of expertise, once you learn how things work with one of them, then using the other is trivial.</p>
<aside class="quote no-group" data-username="Emily" data-post="1" data-topic="5145">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/emily/48/2422_2.png" class="avatar"> Emily:</div>
<blockquote>
<p>I’m learning as I go.  Currently I do not know either.   I would rather only have to learn 1.</p>
<p>With that in mind, would you choose Websocket or AJAX to pass variables between Elixir &amp; VueJS?</p>
</blockquote>
</aside>
<p>I would begin with the fact they are not mutually exclusive. I’ve seen several applications that will use <code>POST</code> requests to send data while listening on a separate WebSocket for pushed real time data. One in particular, could send data across the WebSocket, but for some very good reasons decide not to. However, they could not accomplish listening to real time data the way they wanted over a polling solution.</p>
<p>If you’re just presenting and updating state in the Vue.js application and the Elixir application is for managing state, then there is no reason to use WebSockets besides novelty. If you wanted to learn some things about WebSockets it would be a good exercise. However, if you don’t know how to use Async Web Requests in the first place, you really need to start there.</p>
<p>Also, the things you may learn from using Phoenix channels would not necessarily translate to broader WebSocket knowledge. Phoenix makes using WebSockets easy, but WebSockets are not necessarily simple.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="33687" data-batch-url="/posts/batch_likers">
                        2
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/help-making-a-design-choice-ajax-vs-websocket/5145/28">Post #27</a>
	                </div>
	            </div>
              <div id="likers-container-33687" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="33687"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #27"></div>
  </section>
</div>
    <div class="postbit" id="33702" data-post-id="33702">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="OvermindDL1" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/OvermindDL1/120/2677_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  OvermindDL1
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>I’m not sure why some keep saying websockets are not necessarily simple, even with the base javascript API they are a simple ‘send this string’ or ‘we got an event of a string received’ (or a bytearray or whatever you want to read it as).  Phoenix’s javascript client is a pretty thin wrapper that let’s you register ‘names’ to messages pretty easily (though you could have done that yourself easily too).</p>
<p>Even with HTTP/2 you are assuming the AJAX would be fast without the setup/teardown if the connection stays up, which is not always going to happen.  It can be closed down for any reason, it can be closed once initial information is sent.  It can be closed if the browser is throttling connections from too many open tabs.  Etc… etc…  SSE is interesting, but websockets already supports what it does and with a near identical API as well for receiving events/messages from the server, just no support for sending events back with SSE (hence why using ajax to make those requests).</p>
<p>Also that is a moot point right now anyway, cowboy (Plug’s web server) does not support HTTP2 at the version that Plug requires.  ^.^;<br>
(Hope that gets fixed soon!)</p>
<p>Still though, comparing API’s between ajax and phoenix sockets (even both done with basic javascript) is pretty on par, just websockets is a case where it should always be faster.  Even AJAX requests over an open HTTP2 socket still sends headers and cookies and all sorts of stuff that still causes processing time and have to flow through the whole router and all.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="33702" data-batch-url="/posts/batch_likers">
                        1
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/help-making-a-design-choice-ajax-vs-websocket/5145/29">Post #28</a>
	                </div>
	            </div>
              <div id="likers-container-33702" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="33702"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #28"></div>
  </section>
</div>
    <div class="postbit" id="33724" data-post-id="33724">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="Azolo" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/Azolo/120/2189_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  Azolo
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>I don’t know enough about HTTP/2 to comment, but I don’t agree on the simplicity of WebSockets.</p>
<p>Ok so on simple level they can accomplish the same thing, I send a request across the socket and get a response on the same socket. On that level there is no difference.</p>
<p>Now, requests have a very particular send → receive flow. I send a request I get a response back or I don’t for whatever reason. If a delete succeeds, then maybe I get a 204 response. Let’s do that on a WebSocket, I send a message over the WebSocket and then wait to receive a response. I have to keep track of the fact I made that request so I can inform the user of a success or failure. That is automatic with a regular request.</p>
<p>What if my deletes are expensive, so to provide a good user experience I provide a loading circle and let the user keep browsing and inform them when I’m done. Then they delete 2 more things. With web requests every request will have a response and I will have a <code>promise</code> or something to inform me of what action is succeeding or failing. With WebSockets, I have to keep track of those actions in the messages, then do the work of parsing and managing the messages then invoking a callback manually.</p>
<p>Now, those things are trivial for experienced developers. I knew exactly what I had to do, and knew how to route errors and such back correctly. A junior developer who doesn’t really understand how “AJAX” requests work would not.</p>
<p>There are like 5 other things that Phoenix provides around WebSockets that I can think of off the top of my head that aren’t easy. So I think calling it a thin wrapper is a little misleading, but that’s also a subjective assessment. <img src="https://forum.elixirforum.com/images/emoji/apple/smile.png?v=15" title=":smile:" class="emoji" alt=":smile:" loading="lazy" width="20" height="20"></p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="33724" data-batch-url="/posts/batch_likers">
                        3
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/help-making-a-design-choice-ajax-vs-websocket/5145/30">Post #29</a>
	                </div>
	            </div>
              <div id="likers-container-33724" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="33724"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #29"></div>
  </section>
</div>
    <div class="postbit" id="33727" data-post-id="33727">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="OvermindDL1" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/OvermindDL1/120/2677_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  OvermindDL1
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<aside class="quote no-group quote-modified" data-username="Azolo" data-post="30" data-topic="5145">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/azolo/48/2189_2.png" class="avatar"> Azolo:</div>
<blockquote>
<p>Now, requests have a very particular send -&gt; receive flow. I send a request I get a response back or I don’t for whatever reason. If a delete succeeds, then maybe I get a 204 response. Let’s do that on a WebSocket, I send a message over the WebSocket and then wait to receive a response. I have to keep track of the fact I made that request so I can inform the user of a success or failure. That is automatic with a regular request.</p>
</blockquote>
</aside>
<p>Just pass a tag back and forth, that is what I’ve seen done on every websocket interface to date, and is in fact what phoenix’s library wraps for you anyway.  <img src="https://forum.elixirforum.com/images/emoji/apple/slight_smile.png?v=15" title=":slight_smile:" class="emoji" alt=":slight_smile:" loading="lazy" width="20" height="20"></p>
<aside class="quote no-group" data-username="Azolo" data-post="30" data-topic="5145">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/azolo/48/2189_2.png" class="avatar"> Azolo:</div>
<blockquote>
<p>What if my deletes are expensive, so to provide a good user experience I provide a loading circle and let the user keep browsing and inform them when I’m done. Then they delete 2 more things. With web requests every request will have a response and I will have a promise or something to inform me of what action is succeeding or failing. With WebSockets, I have to keep track of those actions in the messages, then do the work of parsing and managing the messages then invoking a callback manually.</p>
</blockquote>
</aside>
<p>The tag format handles that too, nothing special there.[quote=“Azolo, post:30, topic:5145”]<br>
Now, those things are trivial for experienced developers. I knew exactly what I had to do, and knew how to route errors and such back correctly. A junior developer who doesn’t really understand how “AJAX” requests work would not.<br>
[/quote]</p>
<p>Eh not really, about every RPC system that I’ve ever seen in any language on any system follows the tag style as well, it is quite ubiquitous.</p>
<aside class="quote no-group" data-username="Azolo" data-post="30" data-topic="5145">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/azolo/48/2189_2.png" class="avatar"> Azolo:</div>
<blockquote>
<p>There are like 5 other things that Phoenix provides around WebSockets that I can think of off the top of my head that aren’t easy. So I think calling it a thin wrapper is a little misleading, but that’s also a subjective assessment. <img src="https://forum.elixirforum.com/images/emoji/apple/smile.png?v=15" title=":smile:" class="emoji" alt=":smile:" loading="lazy" width="20" height="20"></p>
</blockquote>
</aside>
<p>Actually for websocket related stuff it handles the tagging (a unique integer per request is its format), it handles reconnecting if the connection dies (with a heartbeat even, where-as if that happened in AJAX your javascript would not be called until the TCP timeout of 30 minutes or a browser internal timeout is hit, which can be very very very long regardless), and it handles abstracting out topics (basically just a namespace for the messaging, which is easy to do yourself by, oh, adding a single extra tag, which consequently is how phoenix does it too).  <img src="https://forum.elixirforum.com/images/emoji/apple/slight_smile.png?v=15" title=":slight_smile:" class="emoji" alt=":slight_smile:" loading="lazy" width="20" height="20"></p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="33727" data-batch-url="/posts/batch_likers">
                        0
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/help-making-a-design-choice-ajax-vs-websocket/5145/31">Post #30</a>
	                </div>
	            </div>
              <div id="likers-container-33727" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="33727"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #30"></div>
  </section>
</div>
</template></turbo-stream><turbo-stream action="replace" target="load-more-container"><template><div id="load-more-container" class="load-more-container">
    <a class="load-more-button" data-turbo-stream="true" href="/topics/5145/load_more?page=4">Load more posts (8 remaining)</a>
</div></template></turbo-stream>