2
比方说,我想建立一个REST服务做笔记,看起来是这样的:客户端ID生成策略
GET /notes/ // gives me all notes
GET /notes/{id} // gives the note identified by {id}
DELETE /notes/{id} // delete note
PUT /notes/{id} // creates a new note if there is no note identified by {id}
// otherwise the existing note is updated
因为我想我使用PUT来indempotent我的服务创建并更新我的笔记 这意味着新笔记的ID由客户端设置/生成。
我想过使用GUID/UUID,但它们很长,并且会使URL记住相当困难。同样从数据库的角度来看,当用作大表中的主键时,从性能的角度来看,这样的长字符串ID可能是麻烦的。
你知道一个好的身份证生成策略吗,它会生成短ID并且当然避免碰撞?
好的。但是,如果您的回复丢失,您如何避免重复创建? – Zounadire 2012-04-04 19:05:39
@Zounadire:你不能(嗯,我相信有一些技巧)。请注意,plain [tag:soap]也不能保证。 – 2012-04-04 19:08:00
完美答案。 – shashankaholic 2012-04-04 20:39:05