-1

I want to design a REST API given the following data model :

Accounts

UserId |  Balance 

user1  |   500
user2  |   200

And given the following Ui that must use the REST service for it's operation for a transfer of funds.

enter image description here

What would be the best way of designing the api for this data model that must also support the transfer UI action?

(URL, HTTP method , body ?)

1 Answer 1

3

I would use a POST as method.

The endpoint would be /api/controllerName/Transfer

And the body would look like this

{
    "from": 123,
    "to": 456,
    "amount": 789
}

from and tobeing user id's, or other identification for the user.

amount being your amount.

7
  • and just hope floats are good for monetary values
    – Ewan
    Sep 19, 2017 at 9:56
  • 2
    To be clear, in a RESTful architecture, "Transfer" in this case is a noun. You are posting a transfer, which is a resource in its own right and which can later be viewed, etc. This is probably what you want anyway, I'm just clarifying because "transfer" can also be a verb. In fact, I'd probably clarify the API more by making the endpoint be '/api/transfers'
    – Paul
    Sep 19, 2017 at 11:03
  • @Ewan so far we've only seen integers discussed.
    – Paul
    Sep 19, 2017 at 11:05
  • 2
    @Ewan isn't that kind of out of context ?
    – TanguyB
    Sep 19, 2017 at 11:53
  • 1
    The main question is how to design the api, not what types he should use. I'm pretty sure his models / prerequisites for them are already stated somewhere. I just added numbers as an example.
    – TanguyB
    Sep 19, 2017 at 14:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.