开发者

Is sending attributes as JSON in an POST/PUT request breaking REST?

开发者 https://www.devze.com 2023-02-04 10:21 出处:网络
TLDR: is PUT /users/1 with user=\"{name: \'John\'}\", as opposed to user[name]=\"John\", OK? I love REST. Recently, I find myself storing a lot of my data in client-side JavaScript objects. It seems

TLDR: is PUT /users/1 with user="{name: 'John'}", as opposed to user[name]="John", OK?

I love REST. Recently, I find myself storing a lot of my data in client-side JavaScript objects. It seems converting them to form-parameters like

user[name] = "John", user[login] = "jdoe"

is unnecessary ugly, since they'll just be reconstructed at the server as something like

{user: {name: 'John开发者_运维问答', login: "jdoe"} }

Advice, Internet? Shall I have the frameworks do the conversion for me? Should I use JSON? Should I start using BSON instead, since it preserves types like Date? :)


As long as the parameters are in the request body (i.e. not sent as query parameters) and the content type is set appropriately, I don't see there being any problem with it, RESTfully.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号