1

Let's say 3 tables

session
-------------------------
id | name | date
-------------------------

speaker
-------------------------
id | name 
-------------------------

session_speaker
-------------------------
session_id | speaker_id 
-------------------------

I've endpoints already in place to do the insertion

POST /session POST /speaker

What kind of REST request should I create to specify the intention to insert into the JOIN table using POST /session or any other method (passing session_id and speaker_id)

Note: I've a PATCH request already in place to activate or deactivate a session.

Question: Basically seeking an ideal REST based solution to handle CRUD based operations for the JOIN table, please advise.

Ben Smith
  • 19,589
  • 6
  • 65
  • 93
user2727195
  • 7,122
  • 17
  • 70
  • 118
  • @BenSmith please comment. – user2727195 Sep 16 '15 at 20:29
  • I didn't want to change the route, `/speakers`, I'm still open to ideas for insert. For `GET`, i took the solution from here, http://stackoverflow.com/questions/32655046/rest-request-type-for-many-to-many-relationship/32700921#32700921 Can you please enhance your answer using this link – user2727195 Sep 24 '15 at 16:18
  • Hi @user2727195, sorry for the delay in getting back to you. I've updated my answer with regard to your use of the speakers route. – Ben Smith Oct 02 '15 at 00:36
  • Did my updated answer help? – Ben Smith Oct 28 '15 at 11:45

1 Answers1

0

You could use the following REST operation for creating the relationship:

PUT speakers/speaker/{speakerId}/session/{sessionId}/

I don't advise using plural names in URLs (e.g. speakers), I'd recommend a singular name such as SessionSpeaker, but as you can't change it from "speakers" I've used it as requested.

You should also use PUT instead of POST for inserting data, as PUT is idempotent i.e. PUT guards against you inserting the same speaker at a session.

To then retrieve speakers information you could use:

GET speakers/session/{sessionId}
GET speakers/speaker/{speakerId}

Another good answer regarding REST and entity multiplicity is here.

Community
  • 1
  • 1
Ben Smith
  • 19,589
  • 6
  • 65
  • 93