2

I'm trying to create a REST service which shows/adds/deletes/edits soccer data in a database. I've made a design of how I could achieve this, but it becomes quite complicated.

For example, when a goal is scored, what URL should I call?

So the question is, am I going in the right direction or do you advice something way different?

enter image description here

Charles
  • 50,943
  • 13
  • 104
  • 142
nhaarman
  • 98,571
  • 55
  • 246
  • 278

2 Answers2

2
  • I agree with Abhiniav's answer except on the fact that PUT should not always be used for editing. It should only be used when you are sending the new complete resource. If you are sending a modification or partial, use POST, or the lesser known PATCH.
  • Reading up on Safe and Idempotent methods should be useful.
  • You would most likely use POST or PATCH to update the goal count: /{country}/team/{team_id}/goals.
  • The biggest reason something isn't REST is because services are not discoverable. Read up on HATEOAS.
Community
  • 1
  • 1
Levi Morrison
  • 19,116
  • 7
  • 65
  • 85
  • I would not recommend using POST for editing because it is not idempotent and partials updates with setter-semantics are. Using PATCH is the imho best advice for partial edits (although not so prevalent as PUT). – mtsz Jan 31 '12 at 01:10
  • @mtsz POST as defined in the protocol is not idempotent, but that doesn't mean you can't implement an idempotent partial-change POST. I definitely agree with you about PATCH, which is why I mention it. – Levi Morrison Jan 31 '12 at 04:11
1

Everything seems fine in your structure except that you should switch PUT and POST. PUT can be used for both updating/creating records. In case you know the resource ID before hand, you can use PUT.

POST is used when you would be creating new resources whose IDs you would not know.

Stackoverflow has a pretty detailed discussion here: PUT vs POST in REST

Community
  • 1
  • 1
Abhinav
  • 38,516
  • 9
  • 41
  • 49
  • This example (http://blog.bucket440.com/?p=209) actually uses POST to update, PUT to create. – nhaarman Jan 31 '12 at 00:10
  • Had not seen that. I usually shy away from PHP based REST frameworks. Most of them have incorrect implementations. :) – Abhinav Feb 01 '12 at 08:54