Chris
Chris

Reputation: 14198

laravel route parameters with post routes vs post parameters

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?

Upvotes: 2

Views: 6964

Answers (3)

Emillion Chandra
Emillion Chandra

Reputation: 21

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?

Upvotes: 2

Thamer
Thamer

Reputation: 1954

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

Upvotes: 0

Franklin Rivero
Franklin Rivero

Reputation: 631

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

Upvotes: 2

Related Questions