HAL - is it a violation to the HAL format/standard if links are in the main body?

前端 未结 3 833
深忆病人
深忆病人 2020-12-04 01:09

According to the HAL standard (see here and here) the links to other resources should be placed in a specific embedded section.

So for instance this

3条回答
  •  青春惊慌失措
    2020-12-04 01:47

    As observable in the specs you posted, you can have links and/or embedded resources:

    A resource's links should sit as a property of that resource:

    {
      "movies": [
         {
           "id": "123",
           "title": "Movie title 1",
           "_links": {
               "subtitles": {
                  "href": "/movies/123/subtitles"
               }
            }
         }, {
           "id": "456",
           "title": "Movie title 2",
           "_links": {
               "subtitles": {
                  "href": "/movies/456/subtitles"
               }
            }
         }
      ]
    }
    

    The alternative would be to directly embed the movie's subtitles resource:

    {
        "movies" : [
           {
             "id" : "123",
             "title" : "Movie title 1",
             "_embedded" : {
                "subtitles" : [{
                    "name" : "movie 1 subtitles"
                    }
                ]
              }
            }, {
             "id" : "456",
             "title" : "Movie title 2",
             "_embedded" : {
                "subtitles" : [{
                    "name" : "movie 2 subtitles"
                    }
                ]
              }
            }
        ]
    }
    

提交回复
热议问题