2

I am implementing a REST webservice and I have a resource (http://localhost/createUser) which is a POST method and takes in a JSON user object.

Now at time t1, a caller calls this API with a JSON object. I make basic validations at time t1 and return response as sucessfull.

But at my backend, this person creation logic takes a while to "really create" and persist it to database - which will take some time - say at time t2 - the user creation is completed.

Now what are the ways for me to notify the caller that this User Creation has been "really successfull"? (or the user creation might fail in between t1 and t2, how to notify this to the caller of this API? what are the ways?)

One way I think of is, create a requestId for each such request and the caller keeps polling another GET API, like (http://localhost/status/requestId) which will give him the result for that request.

Is there any better way to do this?

4

1 回答 1

1

要么在返回之前等待用户“真正”被创建,要么实现类似 getUser 的操作......它可能有一个“正在创建”与“已创建”的状态字段。在我看来,将每个调用映射到“requestId”似乎有点多。

于 2012-05-24T18:48:55.290 回答