<p>I'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{
"CreateReminder",
"POST",
"/reminders/{date}",
CreateReminder,
}
</code></p>
<p>Since my payload is small it could be accomplished with either method very easily but I'm just wondering if there's a best practice for this situation.</p>
<hr/>**评论:**<br/><br/>earthboundkid: <pre><p>There'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 "POST /reminders" with a (usually JSON-encoded) body containing a date. Respond with a Location header pointing to the newly created "/reminders/{id}" resource.</p></pre>
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889
0 回复
- 请尽量让自己的回复能够对别人有帮助
- 支持 Markdown 格式, **粗体**、~~删除线~~、
`单行代码`
- 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
- 图片支持拖拽、截图粘贴等方式上传