Laravel PHP framework as an API  Backend Technology.

Laravel PHP framework as an API Backend Technology.

Laravel is a full stack framework . It means it can be used to develop front End (user side/Client Side) and Back End (Server side) application development. But , it is not compulsory to use laravel as a full stack development framework. Rather, it can be used only for backend technology.

 

What is BackEnd?

Programming has been divided into two virtual parts: front end and back end. Front end is a user visible part, with front end users interacting. Back end is responsible for data management and query processing and some other hidden parts.the backend side can not be visible to the users. 

 

What is API?

It is simply an intermediary ,allowing applications to talk to each other using some Endpoints.

for example. We all have mobile phones so we might see weather applications and climate related data change frequently . It means the Weather application talks with other computer systems to get the actual climate data.  This is the Example of API .

How to use laravel  API backend?

There are several steps involved in using the laravel api. Here, in this paper I explained a get request(getting data from server).from beginning to end.First of all, you have to set up a laravel project. To see how the setup wants to be created click https://appslanka.lk/our-blog/creating-laravel-project.


 

Step 1=> create a controller.

In my example, I  created a TestController for my project. 

  • To create the controller use the following command in your terminal.

Php artisan make:controller TestController.

  • After executing the given command for TestController, you will see the above mentioned picture. Then you have to go to the app/http/controllers . you will see the TestController.php file like given below.

  • Then, write the function you want in the TestController , here I am going to get  the data from the user table. I wrote an index function to get data from the database.

Step 2=> go to the app/routes directory.

  • Under this directory, you will see the api.php file. In that file you have to mention for which URI , which controller function should be executed. Here Route::get('/users',[TestController::class,'index']);

    • Get is a method to request the data from the server.

    • /users is a URI(universal Resource Identifier) to request specific resources.

    • TestController is a controller and index is a function to be executed in the test controller when /user URI is executed.

 

Step 3=> run the URL in the browser.

     .http://127.0.0.1:8000/api/users

 


Conclusion

There are so many front end development frameworks and libraries like React, Angular, Vue js and etc. most of the companies hire front frontEnd and BackEnd Developers separately. As a Backend developer there is no need to develop an entire application . Therefore , as a Backe end developer you can use Laravel Back end API . Front End Developers will use that API to visible the data appropriately to the users.

 

0 Comments

Leave a comment

Your email address will not be published. Required fields are marked *