0

I am making a browser game, it's completely AJAX-based, so I am trying to create a proper RESTful API. So, I have a User model (basically, User has weapon, health and action points).
So I have a users resource. Now, I want to implement user attacks.
Scenario: user with id = 1 attacks user with id = 2.
What I would do is like this:

  1. Send the following info (with POST-request):
    • target_id (well, it's stored in ApplicationController from session)
    • attacker_id
    • weapon_id (weapon attacker uses to attack his target)
      to /users/attacker_id/attack/
  2. Validate if user has enough action points and health for attack, if target is not dead yet. If these conditions fail - do nothing, if they succeed - decrease attackers action points and ammo, decrease target HP. All of this is done in model method called attack for attacker.

Is it a proper way in general or if there is a better, Rails way?
Thank you!

4

1 回答 1

1

当您正在做的是基于资源的 CRUD 交互时,REST 确实最有意义。在这种情况下,你并没有真正这样做——你可以在概念上强制它符合,但我认为你最终会增加不必要和不直观的复杂性。

我会说你只是不使用 REST。只需进行一个攻击动作,即可获取参数并完成其余的工作。

于 2013-07-30T15:15:27.053 回答