1
Currently we have a system that uses Doctrine ORM2, we have our Entities, and themes our DAOS, within our DAOS classes we have several methods that we use to make queries, Change, Insert and Delete Data in the Database.
We have created some prefixes for these operations:
slt => select
lst => list list
get => usually search for a specific ID
alt => change
ins => insert
del => delete
Thus a name for a method in the class User that will insert a new user or seek a specific in the system would be:
insUsuario or getUsuario
So far so good, the problem is that I am creating an api and wanted to use these DAOS methods already ready to do various operations in the bank, I am using the Slim Framework to help me create the api, and I wanted to use the DAOS as follows:
Where:
- Where users => Users
- Where getUsuario => User class method
But I researched and read that using method names in an api is not good practice, and I have classes here that have up to 50 different methods, and I don’t know what to do because I wanted to use these ready-made methods, how could I do this using my methods that are already ready in the DAOS ?
What are the advantages of using the right HTTP methods?, https://docs.microsoft.com/en-us/azure/architecture/best-practices/api-design e http://www.restapitutorial.com/lessons/restquicktips.html
– rray
The idea of REST is to represent a resource so using verbs or actions in Uri names is not recommended. It was not clear in the question you use some mechanism that hits the controller and home with the method name and executes it? The name of your Daos' methods does not need to go to the Union.
– rray
When making a request using this url for example: https://api.com/usuarios/getUsuario/5, I treat the name "usuarios", transform into Usuariosdao, instantiate this DAO class using Reflectionclass and check if the getUsuario method exists in this class, if there are arguments for the method and return the result of the query.
– Lucas Lima
You said that the name of the Daos methods need not go to url, but how will I know, or manage what the user really wants ?
– Lucas Lima
A route will point to the desired method the verb can also help in this case. No need to outsource all methods from one class to the API, only return what is useful.
– rray
I understood then a whole route should reference only one specific method ? And as the API grows I create the routes and also the methods ?
– Lucas Lima
It is not a route by method, the user does not need to know its class structure. The important point is to define the purpose from the API, who will use it? which features/services are interesting to my consumers? which features will I outsource? I forgot to comment on, the site of the restapitutorial has a pdf to donwload recommend reading the sections
Querying, Filtering and Pagination
andResource Naming Anti-Patterns
– rray
I get it, I’m gonna take a look here and I’m gonna follow what you said.
– Lucas Lima