RESTful Identity

I am developing a RESTful web service using ROA (Resource Oriented Architecture).

I am trying to develop an effective way to guarantee idempotence for PUT requests that create new resources in cases where the server assigns a resource key.

In my opinion, the traditional approach is to create a type of transactional resource like / CREATE _PERSON. The client-server interaction to create a new resource should be in two parts:

Step 1: Get a unique transaction ID to create a new PERSON resource:

**Client request:**
POST /CREATE_PERSON

**Server response:**
200 OK
transaction-id:"as8yfasiob"

Step 2. Create a new user resource in the request guaranteed uniqueness using the transaction identifier:

**Client request**
PUT /CREATE_PERSON/{transaction_id}
first_name="Big bubba"

**Server response**
201 Created             // (If the request is a duplicate, it would send this
PersonKey="398u4nsdf"   // same response without creating a new resource.  It
                        // would perhaps send an error response if the was used
                        // on a transaction id non-duplicate request, but I have
                        // control over the client, so I can guarantee that this
                        // won't happen)

, , , , PERSON. , , , .

, , .

?

::

, , , UUID . UUID - , 16 (2 ^ 128). , - , UUID , . , , , .

, UUID (GET uuid/). , , . , , , UUID.

+5
4

HTTP- create. RFC 2616 POST PUT.

9.5:

POST , Request-URI

9.6

PUT , Request-URI.

, PUT URL-, . POST URL- , PUT URL- . URL- POST CREATE PUT UPDATE.

, PUT , /CREATE_PERSON/{transaction_id}. , , , , . PUT URL-, .

, , POST to /CREATE_PERSON. ( HTTP Location).

, REST , URL- . , URL- , , - /PERSONS ( : -)).

, REST API :

  • - GET /PERSONS
  • - GET /PERSONS/{id}
  • - POST /PERSONS ,
  • - PUT /PERSONS/{id} , .
  • - DELETE /PERSONS/{id}

. PUT , , , ( " , key ': -)).

: , POST , HTTP. POST . .

, , PUT ( ) HTTP, URL-. , , URL-, PUT, , POST, . , , ( ).

, PUT , PUT . - PUT URL-, , , . , URL-, API .

, , URL- . URL- , , POST .

+4

, , , .

- GET, , "" . , POST .

, , , . , 500 , ?

, , HTTP - . , , , , , , .

+1

: , GUID

, , GUID. , GUID 2 ^ 128 , .

, GUID . - , .

+1

POST, . , :


POST /persons

first_name=foo

:


HTTP 201 CREATED
...
payload_containing_data_and_auto_generated_id

server-internal identifier will be generated. for simplicity, I would go for an artificial primary key (for example, auto-increment id from the database).

0
source

All Articles