我可以在没有ID的情况下输入吗? [英] Can I PUT without an ID?

查看:96
本文介绍了我可以在没有ID的情况下输入吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在设计一个API Rest服务,该服务允许用户将文件上传到服务器.

I'm designing an API Rest service that allows the user to upload a file to the server.

我认为这是一个PUT请求,它将转到服务器/资源/ID,并在json请求正文中将文件作为base64.

I'm thinking this is a PUT request and it would go to server/resource/ID and have the file as base64 in the json request body.

我的问题是关于此ID.在我的脑海中,我正在将文件传递给服务器,服务器应负责存储该文件并生成一个唯一的ID以供以后检索,然后将该ID返回给客户端(状态良好).

My question is regarding this ID. In my head, I'm passing the file to the server and the server should be in charge of storing that file and generating a unique ID to retrieve it later, and then return this ID to the client with an ok status.

所以我正在考虑这样做,将其发送到服务器/资源,而没有ID,但这可以吗,还是设计不好?

So I'm thinking about doing that, sending it to server/resource, without the ID, but is this ok or is it bad design?

推荐答案

否. PUT的意思是创建或更新",并应带有一个明确的ID. POST适合创建新内容.

No. PUT means "create or update", and should come with an explicit ID. POST is suitable for creating something new.

另请参见:在REST中进行PUT与POST

这篇关于我可以在没有ID的情况下输入吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆