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?

5
  • what is your "challenge"? is it a public string? Commented Oct 24, 2017 at 15:55
  • the challenge is a uuid Commented Oct 24, 2017 at 15:55
  • make it a slug(friendier url), see my answer below Commented Oct 24, 2017 at 15:56
  • It doesn't matter if the users won't see it or it doesn't require SEO inspection. Commented Oct 24, 2017 at 15:56
  • It's you who will see if the challenge uuid can be seen or not if it's ok to expose it to people then use URL parapeter else use a hidden field in the form !! Commented Oct 24, 2017 at 15:57

3 Answers 3

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

Sign up to request clarification or add additional context in comments.

Comments

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?

Comments

0

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.