11
I did some research on the REST API model, but among the many questions I had, I have one that is essentially important.
People always gave examples of route models that looked like this:
https://api.dominio.com.br/account[/{id}]
GET -> obtem o(s) usuário(s)
POST -> insere um novo usuário
PUT -> atualiza o usuário
DELETE -> remove o usuário
So far it works very well, I have the option to handle all users or only one, but only through the ID.
- If I want to select by email or username? How should it be done?
- If I need to pass more advanced parameters to the query, such as a WHERE or an ORDER BY or even a LIMIT, how to do?
@Edit
If possible, I would also like to know the following: in somewhat less abstract operations such as sending a password recovery email, the necessary processes for this should be done in the client application (which would have to make several requests to the API) or create a route that when called performs all necessary operations and delivers a prompt response to the client application?
The operations to send a password recovery email, are more or less in the template below:
- Checks if the user exists;
- Checks if the recovery code generated by the application has already been generated before for another user, to avoid duplicate codes;
- Logs the recovery code;
- Get email template for password recoveries;
- Send the e-mail.
It is not because you are using REST that you are required to use only the PATH, (address path), it is totally acceptable to use querystring
?foo=bar&baz=foobar
, but of course REST is REST, a REST call will not make a number of different things, so a lot of things you will be able to hit on the own PATH. To sum up, you want multiple actions and these actions are surely well solved if divided into different Urls (I believe that Slim has a group of routes, which should help to organize)– Guilherme Nascimento
I suggest you look at these two sites: - JSON API - REST API tutorial With a quick read you will have a good understanding.
– Natan