Is there a correct way to set up this endpoint?

xuanbao · · 649 次点击    
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
<p>I&#39;m setting up a json api using gorilla/mux. Is there a right way to set up this end point or is it up to the preference of the programmer? I could either: 1. Create the payload on the client and POST to the endpoint or 2. Have an endpoint that takes the necessary parameters like <code> Route{ &#34;CreateReminder&#34;, &#34;POST&#34;, &#34;/reminders/{date}&#34;, CreateReminder, } </code></p> <p>Since my payload is small it could be accomplished with either method very easily but I&#39;m just wondering if there&#39;s a best practice for this situation.</p> <hr/>**评论:**<br/><br/>earthboundkid: <pre><p>There&#39;s no one answer but I tend to think it helps to guess about the future. What if you had more parameters? Well then it would be easier to encode them as GET params instead of in the URL. What if it stays the same? In the URL is simpler. Just depends. </p></pre>tgaz: <pre><p>This has more to do with data model design than Go. <a href="https://en.wikipedia.org/wiki/Representational_state_transfer" rel="nofollow">REST</a> is one way to think about the data model architecture that specifically describes URLs.</p> <p>In this case, REST likely suggests &#34;POST /reminders&#34; with a (usually JSON-encoded) body containing a date. Respond with a Location header pointing to the newly created &#34;/reminders/{id}&#34; resource.</p></pre>

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

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