Saturday, 12 November 2016

Full Story Request TO Response


Full Story Request TO Response (Symfony):-


Exactly like the http , Request and the Response are very simple , the real deal is the code which will be written by you which comes is between which will do the computation and embedding the logics that will take you from the Request to the Response .So we can say that your application can be of many types and obviously you would have made some nice also also , it can produce a web page , a streaming video / audio website , a pdf download , a multipart form data where you can input the form as an upload , these are only some of the examples .So how will you make a lot of epic things in between the request and the response and still keep your source code managed in a well manered way .

Thats why Symfony was made !!!


just to give you a glimpse , here is a picture of the structure , how it keeps everything managed .


Front Controller :-

the applications that you would have already made say would be having 5 parts .

1) hello.php
2) Form.php
3)submission.php
4)computation.php
5)Thankyou.php

so its a simple application where people come and visit you webpage and you ask them to fill a form with their details hence you submit the form and do the validations and computations and if everthing is fine then you send them to the thank you page .

So as the name suggests off all the files , it does the respective work , as the user moves ,pages moves and so on .

The better approach to all this is having a single code or a controller which takes care of all the request coming to it and taking care of sending to different places hence to get the response .








so every application out there made in modern times follow this architecture , all the request will come to it and hence based on the routing , it will decide where to send the details for the logics to work on .


So you can actually get an idea , how the things work here in symfony though we will explain everything in details .


No Worries !!




The Flow :-






When you let symfony handle the requests then you programming becomes easier , and whatever requests comes to you application will follow the same patter which is suggested in the picture above .

the incoming request is taken by the front controller and based on a particular files made for the routing purpose , routing.yml it decides internally which requests comes on which url and hence it sends the particular input data to the respective controller and hence the response is provided sucessfully .


An Example :- 


As you can see at line number 29 to 32 , there is a route defined whenever a request is sent to the /contact route , then front controller takes the job , it checks in the routing files and hence it comes upon the conclusion that Oh! i need to send it to the Maincontroller now for getting the response.


Now we will see the main controller class which will make the idea crystal clear .




Here is the source code also :-


// src/Acme/DemoBundle/Controller/MainController.php
namespace Acme\DemoBundle\Controller;
use Symfony\Component\HttpFoundation\Response;
class MainController
{
public function contactAction()
{
return new Response('Symfony Ninja , how are you ?');
}
}


So the front controller decides and send it to the MainController and hence the user gets the response of 

'Symfony Ninja , how are you ?'

Awesome , we are doing great !! Lets move to the next Chapter .





No comments:

Post a Comment