Interactive web page with a GO server

agolangf · · 407 次点击    
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
<p>Hello Redditors / Gophers,</p> <p>I&#39;m (a beginner) trying to develop an interactive web page (displaying a dashboard) with HTML and JavaScript at the client side and Go at the server side (the go server calls multiple APIs and manages the data). I&#39;m doing it this way because I had problems with CORS when I only used JS to directly call the APIs from which I need to get the data.</p> <p>I&#39;d like to know on the server side if the best thing (maybe the only thing, I don&#39;t know) to do is to build an API ? Or is there other options ? Is there any references / examples I should take a look at ?</p> <p>Thanks in advance (and sorry if my question is trivial).</p> <hr/>**评论:**<br/><br/>dAnjou: <pre><blockquote> <p>I&#39;d like to know on the server side if the best thing (maybe the only thing, I don&#39;t know) to do is to build an API ?</p> </blockquote> <p>The term API is soooo overloaded these days ...</p> <p>I suppose you&#39;re referring to a RESTful API. And whether that&#39;s a good idea is pretty much a &#34;business&#34; decision more than anything else. It depends on whether you&#39;re planning to serve different kinds of client applications and whether you want partners or other external systems to interact with your service. If not a RESTful API is of questionable benefit because in addition to implementing the API itself you have to implement some kind of workflow on top of it. But maybe that&#39;s not such a big issue with a dashboard type of thing.</p></pre>decapre555: <pre><p>Thanks for your answer dAnjou. Yes, it would be a RESTful API. It would only serve the dashboard in my case. Is there another kind of API that would be more appropriate ?</p></pre>dAnjou: <pre><p>Look, it&#39;s just HTTP. You can call the endpoints whatever you want, like <code>/gimmethatstuff</code> and <code>/gimmethatotherstuff</code>.</p> <p>You won&#39;t get it perfect the first time anyway. So just go ahead and get your hands dirty :)</p> <p><strong>UPDATE</strong> Of course you can make it your goal to write a proper RESTful API. That&#39;s reasonable. Then the whole thing will probably take longer but what&#39;s the rush, right? As long as you learn something.</p></pre>decapre555: <pre><p>I know how a RESTful API works, I&#39;ve already developed a small one (sorry, I should have precised it earlier). I was wondering if there&#39;s another type of service that I can use / develop and that would be more appropriate in my situation (but yes, in my case, performance isn&#39;t very important as long as it doesn&#39;t take too long to load and display all the data) ? Thanks !</p></pre>dAnjou: <pre><p>Ah.</p> <p>Imagine you have services <em>Foo</em> and <em>Bar</em>. Foo&#39;s API exposes data about cats and it&#39;s latest API version is 3, so their endpoints might look like this: <code>/v3/cats/&lt;ID&gt;</code>. Similarly, Bar&#39;s API is on version 1 and exposes data about locations like this: <code>/v1/loc/&lt;X&gt;/&lt;Y&gt;/</code>. Then you could expose the endpoints <code>/foo/</code> and <code>/bar/</code>. Requests to these endpoints would look like this: <code>/foo/v3/cats/&lt;ID&gt;</code> and <code>/bar/v1/loc/&lt;X&gt;/&lt;Y&gt;/</code>. You can configure your webserver to simply proxy those requests to the 3rd party APIs by dropping the prefix.</p> <p>Just a thought experiment. No idea whether it&#39;s any good. If it is however, you wouldn&#39;t even need any application code.</p></pre>decapre555: <pre><p>Thanks for your answer, that&#39;s interesting. I&#39;ll dig into that.</p></pre>

入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889

407 次点击  
加入收藏 微博
0 回复
暂无回复
添加一条新回复 (您需要 登录 后才能回复 没有账号 ?)
  • 请尽量让自己的回复能够对别人有帮助
  • 支持 Markdown 格式, **粗体**、~~删除线~~、`单行代码`
  • 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
  • 图片支持拖拽、截图粘贴等方式上传