2

Should route parameters only be used for get/delete requests? A user can join a challenge and I want to have an API endpoint for that.

Is this ok:

Route::post('/challenge/{challenge}/join', 'UserController@joinChallenge');

or should I rather pass the challenge id in the post body?

Rob
  • 2,243
  • 4
  • 29
  • 40
Chris
  • 13,100
  • 23
  • 79
  • 162

3 Answers3

2

POST is a perfec solution: "Good Web design" requires non-idempotent actions to be sent via POST. This is a non-idempotent action(It has side effects, it modifyes the state of the DB).

Server logs don't record POST parameters, but they record urls. It's easier to look something through the logs with that design in your scenario.

idempotent: http://www.restapitutorial.com/lessons/idempotency.html

Franklin Rivero
  • 581
  • 1
  • 3
  • 18
2

It is ok

better way:

Route::post('/challenge/{challengeId}', 'UserController@joinChallenge');

don't forget to catch id in your controller

function joinChallenge(Request $request, $challangeId)

please see the reference below

What are the best/common RESTful url verbs and actions?

0

you can pass parametres inside your url but you need to take accept this param by your method joinChallenge(Request $request, $challenge)

Thamer
  • 1,896
  • 2
  • 11
  • 20