Question

Can some please confirm or correct my thinking:

GET test.com/book/books **- get a list of all books**
PUT test.com/book/new **- create a new book**
GET test.com/book/9780142423356/Charles-Dickens-Great-Expectations **- get a specific book**

Is it correct?

How does REST deal with concurrent users - two people writing to test.com/book/9780142423356/ for example?

Was it helpful?

Solution 2

More typical would be

GET /books - get a list of all books

POST /books - create a new book
  - or -
PUT /books/Charles-Dickens-Great-Expectations - create a new book

GET /books/9780142423356 - get a specific book
  - or -
GET /books/Charles-Dickens-Great-Expectations  - get a specific book

POST is used when the unique identifier for the book is not known. PUT is preferred when the creator of the resource knows the unique identifier.

As far as concurrency management, the HTTP spec has headers that will help, such as etag, if-match, and if-none-match.

OTHER TIPS

REST doesn't worry about concurrency because REST is programming model only. It is up to you on how concurrency is managed.

PUT is for updating, POST is used for creating new resources, but it is up to your implementation that while updating if resource doesn't exist you can create.

With respect to concurrency you would have to manage that by yourself.

If you are using any layered approach for data CRUD operations, you have to code the DAL to handle concurrency.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top