Representation of REST resources with PUT and GET compatible links

I was asked to design and implement a RESTful API, as well as explore best practices, but so far they have only an empty concept of representing resources. Most of the available examples that I found seem to pretty much focus on API clients that work with related structures using the GET series.

I watched:

http://www.restapitutorial.com/media/RESTful_Best_Practices-v1_1.pdf

http://www.youtube.com/watch?v=HW9wWZHWhnI

among other online resources (I am limited to two links, sorry, I can’t list them). They are all great, but don't really touch on my design issue.

Most of the best practice documents offer two things that conflict slightly for me:

1) The REST service should represent data relationships as links between resources

2) The “PUT” request from the client should be a complete view identical in form to the view observed on the server.

The problem from my point of view is that links, and possibly quite a few other properties in a typical resource, are read-only, so they cannot be updated. The server seems to be shoudl waiting for them as is, and returns an error if he thinks the client is trying to update them. In fact, when I look at a typical resource represented in JSON, most of them are data that logically cannot / should not be replaced. For instance.

{
 "link": { "rel":"self", "href":"http://example/project/12345" },
 "team": {
    "link": { "rel":"self", "href":"http://example/project/12345/team" },
    "title": "The project team"
  },
  "title": "The Big Project"
}

Here, at best, only two title texts will be available for writing to the client on this resource (team membership can be changed through a command link).

, PUT "" , ( , , - , )?

- REST ? REST, HATEOAS, , , , "". , "" REST , , , , , , .

REST , GET PUT, , , , . , , , GET., , PUT , (.. , , , , ).

+5
2

"" , . , , . , "body" , :

, , , , ( HTTP PUT POST, ) - ; () , . , , . "" , .

( , , ()). , , , , ; HTTP- ( ). , - .

; . , , . , , .

+1

, GET , , ( ). , , , ( ) GET. .

HTML - <head> <body>, ; text/html application/x-www-form-urlencoded, , - , - . POSTing , application/x-www-form-urlencoded - !

, " REST". . HTTP- API, REST. API . API HTTP.

, - PUT. , , :

  • -

, , /cars. , , DELETE /cars/1, DELETE /cars/2... .., PUT /cars . , .

- , , /cars/1, :

{
  "model":"Model-T",
  "mfgr":"Ford",
  "colour":"black"
}

URL-, /cars/1/mfgr, Ford , , {"mfgr":"Ford"}. URL /cars/1 . - URL. , URL- .

, HAL JSON.

+3

All Articles