开发者

Ruby on Rails: Rest API to submit a list?

开发者 https://www.devze.com 2023-02-12 16:30 出处:网络
I am confused about RoR\'s handling of REST lists. The Rails 3 routes magic creates (among others) POST /items create one item

I am confused about RoR's handling of REST lists.

The Rails 3 routes magic creates (among others)

POST /items create one item
GET  /items list all items

Now, I want to have exactly this PLUS the possibility to POST a list of items (in XML).

What's the best way to do it?

Semantically, POST /items to me sounds about creating a list, not a single item Can I '开发者_StackOverflow社区overload' this in the controller? Or do I need to create a new routing?

Thanks


You can code your controller to either accept a single item or an array of them. This isn't in any way reflected in the routes, but only concerns your controller, as POST-parameters are not specified in the routes.

It is accepted (and generally assumed) behavior to accept a single item there. But you are free to accept whatever you like.

0

精彩评论

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

关注公众号