Master / Part with REST

I am sure that this topic must have been closed earlier, so I am glad that I pointed out any articles, etc. that I might have missed during the search.

I need to implement a very simple REST API to add and retrieve records in a master / detail relationship. Below are my two options:

OPTION 1

POST /master
POST /master/[id]/details
GET  /master/[id]
GET  /master/[id]/details

PROFI

  • A little more "RESTful"
  • Can extract fine data for performance

REDD

  • A master does not make sense without at least one detail. How to handle atomicity? Compensate for DELETE on the host device if the drillthrough fails when adding?
  • Multiple calls required to retrieve a set of masters / parts

OPTION 2

POST /master_and_details
GET  /master_and_details/[master id]

PROFI

  • Easy atomicity control

REDD

  • More complex management structure
  • GETs should return the whole structure (not always efficient)
  • "RESTful"

,

+4
3

REST 1, 2 - http api.

, , , . , api . , .

, , .

1 - , , . 2 .

+2

, , , .

: . ( "", , , "" "" ). () . http://tools.ietf.org/html/rfc6573 .

GET ( ) . POST/PUT POST/PUT .

GET/PUT/POSTED . , , . , :

GET /detail/{detailKey}  - gets specific detail
POST /detail  - creates new detail
GET /master/{masterkey}/detail  -- gets all details for master
GET /master{masterkey}/detail/{detailkey} -- get specific detail

, POST .

, URI. , , : detailKey masterKey, 404? , .

, , , , . , {detailKey}, , ( ).

+2

1, 2 REST. , Master + Detail.
Detail Master ( ), , Master Detail Master.
Detail .
GET /master/1 GET /master/1?detail=true.
POST PUT . "" Detail. JSON:

{
  "data": {
    "name": "master",
    "detail": [
      {
        "name": "detail1"
      },
      {
        "name": "detail2"
      }
    ]
  }
}

A POST Master name "master" 2 Detail Master.

@ElroyFlynn, Detail Master, .
Thread POST s. a Thread Master, POST Detail. POST , ( - GET /post?max_age=1h).

And I do not agree that Masterwithout Detaildoes not make sense. There may be times when this is not the case, but in the case of the forum a, Threadat its discretion, does. For atomicity:
It depends on the case. If you delete User, you usually keep it POST(even here in StackOverflow). If you delete Thread, I think you can delete POSTat.

0
source

Source: https://habr.com/ru/post/1613136/


All Articles