What kind of problems do routes solve?

Asked

Viewed 100 times

2

Every framework in MVC architecture or even other architectures I come across, I find it almost mandatory to configure routes. However, it’s not clear to me what kind of problem that solves, and I can’t find literature that helps much. The common is to find content focused on a particular tool or framework, treating routes as something obvious. Django, Angular, Laravel, MVC 5 . NET, virtually every material that addresses the subject treats as if it were something you already learned in college. I have an intuitive hunch, just like I did on GET requests in PHP. He used a lot to call includes, using PHP to generate templates with includes (avoiding PHP Injection of course), reusing much of the code, and even rewriting new paths with a few lines of code. Can routes be considered analogous to these primitive web application techniques? I believe the question "What kind of problems routes solve ?" well direct and not broad, I hope you will interpret so, and that it can help many developers. Consider editing this text as contextualization, not a long question. Thank you all!

  • 1

    Oi Sérgio I think this would be a doubt more for the stack exchange because it is something more technical than technical

  • Routes are found in virtually all existing frameworks, and there is extensive knowledge of what they do. What I don’t see in discussion is what kind of problems in practice they solve. There’s practically nothing theoretical about it. The question is very empirical indeed, which by definition is not theoretical. In short it would be: Why not simply point out addresses with variables or constants, because each functionality practically has to have a route? That sounds very technical!

  • 1

    @Marcosbrinner pauses to momentarily ignore the fact that many theoretical questions here on the site have positive and huge reception from the community

  • The routes are in virtually all frameworks, various architectures, we use daily, and yet you consider this a theoretical issue?

  • I imagine myself at a fair asking the price of a fruit and someone saying that this is too theoretical a question.

2 answers

1


SOLID is the principles of object programming and helps us write better code. The first is the Single Responsibility Principle (SRP) or Single Responsibility Principle. This principle states that each part of the code should be responsible for only one specific task.

With a route library it is possible to perform checks on entries (treating special characters, for example), to work better on http verbs (POST, GET, etc), among others.

When developing the code, the changes that need to be made are more practical, since they are concentrated in only one place.

See an example with Laravel:

Route::get( '/',         'OrderController@index' );
Route::get( '/nova',     'OrderController@create');
Route::post('/nova',     'OrderController@store' );
Route::get( '/ver/{id}', 'OrderController@view'  );

With code organized this way, it is possible to change the Urls without major problems, as well as what each route does.

0

Routes more easily solve the problem that you need to have a physical file for each URL and allow more friendly URL writing.

When the concept of routes did not yet exist, each URL was a physical file on the . html, . php, server. Asp, etc. Imagine managing a customizable system that has more than 1,000 pages in physical files.

In a way, it may look like the concepts of includes. But it’s wider. Think of a URL that receives a request to generate PDF or Excel. Most of the time you don’t need a page for that just return the content to download.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.