I was wondering, I'm trying to clean up my rest api, Lets say I have two "objects" like users and photos and I want to have an api that allows users to comment on both these objects. An example of the route would be something like sending a post request to
api.domain/comment/user/1234 with a query string parameter comment
and a comment to a photo would be like
api.domain/comment/photo/1234
it would be cool if I could just have a method in my rest controller like
public function post_comment($type = "photo", $id = null){
}
where thats only routed if type == "photo"
so basically the 2nd routing param is what type of object is being commented on, what I'm basically doing is having a publicly exposed method like
public function post_comment($type = null, $id = null)
Yeah I thought about doing that too, ill try it out.
As per your suggestion I've been trying to follow the design of other popular api's I wish there was a standardization. So for the above example it would be a POST request but some params are in a query string, OR you could even have the ID as in the form data and do it all that way, and now im seeing some api's where the incoming data is in a json string.
I hardly ever use the query string, selection parameters (like your 1234) are URI segments, the rest is in the request payload, in JSON.
A GET request is used for reading, a POST for updating. There is also PUT, PATCH and DELETE that you could use (not all webservers support these by default).
The only place I sometimes use the query string is for stuff like column sort info, for example "/controller/index/16?sort=name&order=desc".