david david - 1 year ago 52
reST (reStructuredText) Question

Can I PUT without an ID?

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

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.

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.

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


Answer Source

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

See also: PUT vs POST in REST

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download