API DATA is very tedious and annoying

Is there a way to make endpoints via code?

Currently you have to create endpoints, assign functions to them and then if you want to call these functions use context.

The act of creating an endpoint:

1 - go to page
2 - Create the endpoint
3 - Create a function and link it to the endpoint
4 - put the specific code from the web
5 - try every time…
6 - and calls to another function with contexts and returns between functions there are too many things that could not go well.

It’s too tedious.

In php:

Route::get('/findAll', [Controller::class, 'findAll']);
public function findAll() {return DB::collection($this->table) ->get(); }

in nodejs

In the time that I add 1 endpoint in Mongodb, with the other languages, I create 100 or 1000 endpoints if I use ctrl+v.

Could you think of a better way to do this?
An improvement could be implemented by code, but the improvement could take years since the way they have it implemented is too archaic.