2
JhonDoe
6y

hello folks, any help would appreciated :). serious question about designing/developing a rest backend.

here is a little insight: I want to reduce the endpoints for many CRUD operations as I can. So for that approach I defined a set of "dynamic" routes like /:moduleName/list, /:moduleName/update and so on.

Now I want to also reduce hardcoding as much stuff as I can for the front end. like I want forms/view/components to know which fields can be sent in the "/:moduleName/xxx" endpoints from above. So I'm thinking to make some /:moduleName/list/map, /:moduleName/update/map endpoints that tells the frontend which fields/keys can be sent for X or Y operation.

regarding design/security concerns Is that a good approach? do you know any other approach that's like to what I want to achieve?

Comments
  • 0
    Maybe I do not fully understood but

    if you are calling more than Read or Search routes, how are you gonna handle all the different attributes of your models if you use a dynamic routes?
  • 1
    Sounds vaguely like grpc.
  • 0
    @cursee yo. I got an orm running, so after getting the :moduleName param, I go to the orm regarding that table and check the fields
  • 0
    I'll elaborate if I'm not clear :)

    here's some logic present in those endpoints

    1. I got the module name from the request

    2. I search in the models if there is model matching that name

    3. I get the fields from the model file

    4. do some validations here now that I got the field names, types and whatnot

    5. call find, update, remove or whatever operation is needed
  • 2
    If i understand right, I did something similar in php using class introspection of my model and annotation ( can use many different thing tho ). I did the security using the annotation and didnt seem like an issue until POST PATCH PUT and DELETE but at least i got all my /:entity /:entity/{id} /:entity/{id}/:collection and all the filters going along with them
  • 0
    @v1nc3nt67 cool! Thx, I think I'll keep with my approach then
Add Comment