Transcripts
1. Introduction: Hi there, and welcome to this
class on LAL API Basics. Build your first restful API. My name is Shah, and I'm
a web developer with over 14 years of experience in building full
stack applications. In this class, I'm exited
to guide you through the process of building
a simple but powerful, restful API using LAL, one of the most popular PHP
frameworks in the industry. Whether you are just
getting started with al or looking to start
on your beacon skills, this class is designed for beginners who
want to understand how APS works and how to
create them the right way. Together, we will walk step
by step through setting up Al creating routes
and controllers, working with the databases
using equivalent and returning clean JSON responses
using APA resources. By the end of this class, you will have built a fully functional student
registration API with full curd operations. So if you are ready to level up your aol skills and build
up your very first API, let's dive in and get started. See you in the first class.
2. Composer Install: One. Welcome to this lecture. In this lecture, we are going
to install PHP composer. Let me show you further, go to Google and
search PHB composer. Go to composer official
website, click on Download. Here, you will see
the apps and two, download composer
setup X click on. The executable file will
get download Once download, so in folder. Let's install. Select Install for all user. Click Next. Select your
PHB path. Click Next. Again, next, click Install. It will take two to 3 minutes. You have successfully
installed compressor Verson. Let's our compressor Versum. Go to your terminal. Type composer V. C, our composer resin is
2.8 pin four. Thank you.
3. Install Laragon: Hello, won. Welcome
to this lecture. In this lecture, we are going to install Laragan
asever Local server. Let's begin. Go to your
browser and search aragan. Go to argon Apical website,
click on Download. It will take you to
the LarganOL website. Here, you will see the ps
and two download Laragan. Click Download. The executable
file will get download. Almost 173 B. It depends on your
Internet speed. I'm going to pass this video ni. Download has been completed. Let's open this file in
our download folder. Let's begin our installation. Select Language. Click Okay. Select the folder
where you want to install Aragon. Click Next. Again, next, and click Install. Our installation
has been completed. Click. Thank you. See you on next picture.
4. VSCode Install: Loan. Welcome to this lecture. In this lecture, we
are going to install Visual Studio code for our
project editor. Let's begin. Open your browser
and search VS code. Go to Visual Studio
official website and click on Download. Here, there are multiple
operating system available. Select your operating system. In my case, it is Windows the executable file
will get download. It will be around
100 MB in size. The downward speed,
it depends on your Internet speed and system configuration.
Almost finished. Okay. Our download
has been completed. Click son folder. This is our EXE file. Actually, I have already installed VS code
on my magazine, so I'm not going to
install in this video. Just follow the instruction and finish your setup. Thank you.
5. Laravel Install: Hello, everyone. Welcome
to this lecture. In this lecture, we are going to install Law in our
local environment. Let's get started. Open your
browser and search Law. And this is a official website, lawl.com, go to the
official website. From there, you can find
the Opsin documentation. Click on Documentation.
On the top right, as you can see, this is the latest version
of owl, which is 12. And on the left side, there is prologue,
do release notes. The latest version of the ravel, which is released done
24th, February 2025. And as you can see here, Laoltwel continues
the improvement made in Laowleleven point x by updating upstring
dependencies and introducing new starter kits for
react, view, and live. Okay. Now, go to getting started
and go to installation. Bow down a little bit. To install owl, we need to
install PHP and composer. We have already installed
in our local environment, copy this command,
composer global ke Al slash installer, copy, and go to aragon click Start al Goerinal and pase a command over
here and hit end. Okay. Go back to LA
official website. And to create a new application, we need to run this command, LAL Nu and our project
directory name. Copy this and go to terminal
again and page the command. Instead of example app, let's name it our
project as A dash APL. Hit Enter and it will ask
you some questions like, which starter kit would
you like to install? Select none. Our installation is in progress. Which database will
your application use? Select MySQL Default
database updated. Would you like to run the
default database migration? Select no as for now. We will migrate it later. Would you like to
run NBMNBMunbil? Select no as for now. Fine. Next, we need to create database
for our LAL project. Go to aragon and go to database, click Open and here on
the agon dot Mays gal, right click and you will find the Opson create new
and select database. Create new database for
our Law Pull project. Let name it as Law
and the sce APL. Click. Here is our database. We have successfully
created database for our aaalPject and
go to LaganTeminal, move inside our
project directory, which is CD space all APAF here, type codspacdt I will open our project into VSCO. Okay. And from there go
to dot ENV file. Here, we need to
configure our database. Here you can see our
DB connection as MSTLHstname pod number 3306, and our database name is
lalTwelUnerscore API. Use the name for
our local host root and there is no password. Okay, we successfully configure our database connection
in DNV file, close this, and go back
to LaraganTominal. Now we are going to
migrate our database. PHP TSNEnter here, there are three tables
have been migrated. Let's check with our database, go to database, and this
is our database, right? Click reference.
Here, few tables has been successfully migrated. Okay, right, we are successfully install aol in our
local environment.
6. Laravel File Structure: Hi everyone. Welcome
to this lecture. In this lecture, we'll walk
through Al file structure. The Al file structure
is organized to make development inti with separate directories for
different responsibilities. First, there is an app folder. The core application
code reside here, including the business
logic and models. Inside app folder, there is an STTB model
providers and view. Inside HDDB there is
controller folders. It contains controller
class for handling request, and there is request folder. Request, it's a custom form
request for Valdes and logi, here we have model folder. It contains equivalent ORM model representing your
database tables. And then here we have
boost up folder. It contains AbdtPHB which
boost up the application. And there is cache folder. Stores frameworks generated
files for performing optimizations and there
is convict folder. It contains configuration file for various parts
of the application. Example, Abt PHP, database, and Q PHP, et cetera. And there is database folder. And inside database folder, we have factories,
migration and CDs. Inside factories, define model
factories for generating test data and the migration contains migration file for
database schema changes. And CDS it contains classes for populating the
database with initial data. And here there we
have public folder. Public, it contains publicly
accessible directory. For example, images, style sets, all our files will come
inside this directory only. And here we have
resources folder. Inside resources,
there is CSS JS views. Inside views, Blade template for the front end
applications are there. In Then we have routes folder. It contains all the
routes for our website. There is web dot PHB, routes for the web interfaces. And there is Console dot PHP, defines custom artisan commands. And then we have storage folder for storing files generated
are used by the application. App folder, here we have
framework and logs. Inside logs, all the
application log files will be stored under p folder, custom applications
file will be created. And there is test folder. It contains test cases for
unit and feature testing. And then we have vendor folder. It contains all the
composer dependencies, which means third
party libraries will comes under
this folder only. Here we have dot NV file. Environment specific
configuration file. Here, we define variables like database credentials,
APIs, et cetera. Then there is an artisan file, a command line interface
tool for variable, various tasks like
running migrations, creating controller
models and middle was. There is an composer dot JSMfle defines PHP dependencies
and Auto loading. Here we have package dot JSMf for managing JavaScript
dependencies and friend en tools. Thank you.
7. API ROUTE: Heller one. Welcome
to this lecture. In this lecture, we are
going to install API route. Under the route folder,
there are only 35, which is console and web. Inside web, all the routes related to our Front on
will be present over here. And by default, there
is no AP route. Now we are going to install it to install AP route,
run this command, PHB, artisan install Poland API. Okay, or new database
migration has been published. We like to run all bending
database migration selects. Okay, personal
access token table has been migrated
into our database. Go to database. Collect our database DVRs. As you can see, there is a new table called
personal access toque. And also inside Routes folder, there is a new file
called ab dot PHB, which is responsible
for all APA routes. Here, we need to mention
our APA routes. All right. In this lecture, we
have successfully installed APA route
for our project. See you on next
lecture. Thank you.
8. Test API: Hello, everyone. Welcome
to this lecture. In previous lecture,
we have successfully installed AP route
for our al project. And in this video, we are going to create
our first APA route. Go to terminal,
open new terminal. And here, now we are going to create a new
controller for our AP. To create a new controller, run this command, PHB, Artisan, make colon, controller,
inside API folder, API slash. Then we create a new
controller card. Test. API controller. Enter. It will create a new file inside our RGTBler
inside controller. There will be a new folder
called EPA inside APA, there will be a new file
test APA controller. This is our test APA controller. After creating controller, we need to specify our APA route. Command this out for now. We will enable it later. Okay. Here route, colon, colon, G here we need to give our URI, which is Ap endpoint. Let me say it does Test. Next, we need to load
our APA controller, which is Tiest API controller, make sure that it has
imported at the top, colon colon class, and here we need to
mention our method. And give name for our out. Save the file. We have created one
test out for our API. Now we are going to
check our route list. PHB, artisan, Route colon list. I will show all the routes
in our Lol project. And here is our newly
created APA route. Just get method, and the URI of our route
is AP slash test. Okay. Next, we need to create a
method in our test APA control. Or method name is test. And here you are going to simply written API works. Go to your browser and and here APA our AP, slash test. As you can see,
this is our output, which is we have written inside our AP controller
method, APA works. Now we are going to wten the same response
in JSON format. Further written response JSO status, success, and
message, let it say. API works. Save the file, go to a browser, simply
refers the page. And as you can see, our respon
is in JSNFmat. All right. In this video, we
have successfully created controller for our API, and also we have mentioned
our route in routes apt pHB we have created method
in our test APA controller, and here we have returned our
response as a JSON format. Thank you. See you on next lich.
9. Install Postman: Hello, everyone. In our project, we are going to use
Postman as our API client. Let's see what is Postman. Postman is a powerful
API platform that simplifies API development,
testing, and collaborations. It provides a user friendly
interface to send request, valid responses, and
manage ABs efficiently. Used by developers, testers,
and teams worldwide, Postman supports risk,
SOP and graphule APIs. I E features. Send APA request. Test endpoint with G, post, put, delete, et cetera. Organize endpoint into reusable and sharable groups
by using corrections. We can dynamically switch
between development, staging, and protection by using
environment variables. Testing. Valid our APA responses with JavaScript based tests. Documentation, automatically generate and share
AP documentation. Why use Postman? Ease of use. Ititive interface and templates started quickly. Collaboration. Teams
can share APIs, collections, and
results automation. Save time with
automated testing, integration works with CICD pipelines to
streamline deployments. Comprehensive protocol
support, analyse rest, sort, graph cual and both. Next, we are going
to install Postman. Go to your browser,
search Postman. Go to Postman official
website, ww.postman.com. Here you will see the Option
two, download Postman. It will take you to the download
page of Postman website. Click Window 64 bit. The executable file
is downloading. Our download has been completed. Now we are going to
Install Post Mal. Okay. We have successfully
install Posterman. You can create account by
clicking Create Account Upson. It will take you to web browser. And here you need to input your email address and
use a name and password. Click Create free account
to create account. I have already created
account with Postman, so I'm going to
sign in directly. I already if you are already
registered with Postman, you can sign in using your
credential, click Sign in. Okay. We have successfully
signed in postman account.
10. Student Registration API: Hello, everyone.
Welcome to this Dixon. In this section, we are going
to create a very basic API, which is student
registration API. And here we are
going to create APA for student registration
and also we are going to create a APA get all the student
data and how to get a single user data by using
APA and also we are going to create APA for editing
student data by student ID, and we're going to create APA for deleting student from API. Let's get started.
First, we're going to create a new migration model. PHP, Artisan, M, colon, model, which is student and also create migration for
this model by using Dacium. All right. Here, there is two file has been
created Ous model five, which is under app
model student PHP. And another file
or migration five, which is created under
database migration. And here is our
migration table five. Okay. Let's define
table columns first. Table, string name. Table, string, E. It must be unique. And let's create another
column E num and column name, gender, and allowed absence, which is male, female. Okay. Save the file. Now we need to migrate this
table to migrate table. You need to use this command,
PHP Artisan, migrate. I enter our newly created table has been migrated
into our database. Chick the migration, go to
database as you can see, here is a newly created table, which is student
and here we have a field name, Emil and gent. Okay. Next, go to models,
openstuden dot pHB. And here we need to make all
the fields are fillable. Protector fillable inside array, specify our column name, name, EI and Jen. Okay. Save file. All right. We have
successfully created model and migration for our student
registration API. And the next video, I will show you how
to create route and controller method for our student registration
process. Thank you.
11. Student Data GET API: Level one. Welcome
to this lecture. In the previous lecture,
we have created model and migration table, and we have migrated
our table into our database for
our student API. And in this lecture, I will show you how to create
route and controller for our student registration
API. Let's get started. First, we are going to create new controller power
student registration APN. To create a controller, run this command, PHB, artisan, make Colon controller,
and inside API folder, APSAs student API controller. And this is going to be
a resource controller. And there's this API, a tender. I'll create a new file under
our folder inside our HTTP. Go to app HTTP controller. Inside API folder,
there is a new file called student API Controller. And as we created
a resource route, there is a default method
called index store, show update and destra. From index method, we can get all the student data and this
method we can use it for create student and
this method we can use it for getting a single student data
and this method, update, we can
update student data and this method we use
to delete student data. Bye. Next, we're going to create route for our
student registration, go to routes API, Trout colon colon API resource, and endpoint students here load
our controller, which is student API control. Colon colon class.
Save the file. Now we are going to sack our route list by
running this command, PHB partisan route list. Okay, go at the top. And as you can see, there are a few APAs created since we
are using a resource route. Here is our get method,
AP slash student, and here's another
method called post to create student data. And here is another
method, student slash. Here, we need to pass
a student ID to get a single student data and here put our patch to update
the student data. And here is another APA called delete APA to
delete the student data. Okay. Now we are going to
create our logic part. Go to student AB Controller. On the index method, we're going to get
all the student data by loading our student model. Student colon colon, get and store the result in a
variable called students. Here we are going to
return our response data. Return response. The and format. Status. Success and data will be our student data. And here, mentioned the
status goal as 200, which is response for success. Success response. Now we are going to test this API in
our postman AB client. Open Postman. And from the collection section, click on the play symbol to
create a new collection. Select Blank colexon and
name meters Laural API. And click Add a request. Get all students. Here, we need to specify
our method name, which is get and
here we need to give our API endpoint and
our APA end pointers, check our Out list. Aps students. Before that, we need
to give our URL, which is L las pot Okay. Enter, I sent. And as you can see, we
got success response. Here is the status success, and there is no data. That's why we are
getting the MTRA and here is our status sce
200 recs successful. The server has
responded as required. Okay, on the next lecture, we will create AP for
our student registries. Thank you. See you
on next lecture.
12. Create Student Using API: Layer one. Welcome
to this lecture. In this lecture, we
are going to create a new student data and we store
it to our database table. For this, we need to
use this AP method, which is inside our
student APA controller. Our method em is store and
our AP method is post method. Open student AP Controller. And go inside the store method, first, we need to validate
our input request. For this, we need to
use validator facades, validator colon colon M here we need to pass
two parameters, which is request data and another Owners,
our validation rules. What are the fields we have in our student table?
Check our database. We have name field, email field, and gender field, right? So all the three
fields are required. Name which is required
and Emil Also required. Gender, AR. And here we can add few more rules by
separating pipeline symbol. That's a minimum four character. And Emil face unique and our table name is students and our column
name emails with. If there is any
validator error means, I validator fails, we are simply written
the error message in JSON format, written
response, Jason. Status file messages, we need to return
our valid data Rs. Okay. Save the file and go to Postman and inside
our a AP collection, create a new collection. New request. Name it does create
student, and here, our methods post method, and our AP endpoint, which is Ap students. And as you can see, method post and our Ap endpoint
is a students. Okay. And inside our body, collect raw data and
select as JSON and simply send without passing any
data to check whether our validation is working
or not, click Send. As you can see, status message, the name field is required, email field is required, gender field is required, and here we got 200 response. We need to change this
status quote and go to here, set 400. To mention this record
request is bad request. Click send, as you can
see, 400, bad requast. Okay. Our validation
is wping fine. Let's test it out. Our additional validation.
As you can see, the name field must be
at least four character. Our additional validation for the name field is
working fine here. Okay. Now we are going
to save all the data. Request of all getting
all our request data, which is name, email, gender, and store it to the
variable called data. And now we are going to
load our student model, student colon colon, use
method to create data, which is create and here we need to pass our data as a bi. It will store data into our database table,
which is students. Once the student
data has created, we need to written response, as a success response,
written response. Status, success, and message. Let it say student
created successful. And our status score 201. Okay, save the file,
go to Postman. Okay, name, name
agenda. Click Sent. As you can see, we got success response
status succes student created successful. Go to get student API. We got one response. Here is our student data, which is we have
created recently. Fine. We have successfully
created APA for our create student data. Let me test it out whether
you're going to create a new student data
which is student two with the same email address, we would get the El message. This is what we have
mentioned in our APA method. The email must be unique, right click send the email
has already been taken. Our validation is
working fine. All right. In this video, we have
created API method and store the data into our
student database using APA. Thank you. See you
on. Next lecture.
13. Get Single Data: Level one. Welcome
to this lecture. In this lecture, we
are going to get a single student
data from our API. And to get a single
student data, we need to use this API, AP slash students
and from the URL, we need to pass the student ID, and our AP method name is SHOP Open our student
APA controller. And go inside the show method. And here, we're going to load
our student model and find. Here we need to pass
our student ID as a parameter and store the data into the
variable called student. Okay. Give student, then we're going to
return response. Access and data will
be our student data. If there is no student, then we are going to return. Then status as failure. Status fail, and message. No user form. With the status que 404 and
here with the status que 200. Go to Postman, create
a new request inside our collection and
request and name it us get student data. And our APA endpoint. Which is ap students,
then student ID. Was this student ID
one, click Send. We got the single student data. And here, let me
pass invalid ID, we'll get status we, no user form or
APs, cooking, fine. Let me create another student. Go to get all student here, we have two data and go
to get student data, Bypass the IDs to, and we got the data for
the student ID two. All right. We have
successfully created a GPI to get a
single student data. Thank you. See you next picture.
14. Edit Data By ID PUT API: Level one. Welcome
to this lecture. In this lecture, we are going to update the
student data through our APR and our API
endpoint is Apsuts. Here we need to pass
our student ID and our API method is we can
either use Put or patch. Now here we are going to use
Put method and go to student APA controller and go
to the update method, and here the parameter, you're getting the request
and the student ID. First, we need to validate
our input request. Validata validata
facades, colon, colon, make and here. We need to pass to
argument which is our request data and another one is our
validation rules, right? Name required and
minimum four characters and EMI, which is required. It must be unique from
the table students and the column the column name
is EMI and except the ID, which is request which is our parameter ID. And the Gena required. Okay. If there is any
validation error means validator fails writen
responses error. Status p and written
message as validated here. Okay. And with the status cue, 400 further bad fiqest. Okay. After validation,
we need to check whether the student is exist
in our database or. Further, we need to load
our database first. We need to load our model first, which is student
colon colon fine, pass our ID as a parameter and store this result
in a variable student. If there is no
student not student, written response, Jason, and the status fail. Message, no student form with a status quo,
four not four. If there is a student, then we are going to update the student student of Ni
which is from our request, request of Ni and
student of EMI, which is from our request, request of Emil Okay student of ender, which is also from our
request a request of Gender. And finally, save the student by calling save method. Okay. Once student data
has been updated, we need to return a response
as success response with the updated student message student data updated successfully. The data, and just go into our updated student data Lav
stud with a status code. Save the file, go to Bosman
and create a new APA request. Let's says Ed student. Method as put AB endpoint, which is ApudenO student ID. Now we are going to edit the second student
pass this ideas two and I'm going to change the name as this. Non past it over gap. And here, change the name as student Test three. EmilizTs three and
gender this may click sent we got error. Here we are getting this
error column not found, which means our email
validation is not working. So here, required
unique student email. Here, we need to
remove this exert. Save the file, and now
it's working fine. Okay, here the student data has been updated successfully, and let's give the invalid ID. Status pile 400 bad request. The email has been
already taken. We got the status
spile no student form. In this video, we have
successfully created our API for updating
student data. The next video, I will
show you how to delete the student data
through our API. Thank you. See you next lich.
15. Delete API: Play. Welcome to this lecture. In this lecture,
we will implement the functionality to delete the student data
through our API. To delete the student data, we need to use this method, destra method in our
student AP controller, and our AP method will
be delete method. Go to student API Controller. And go to the destry method. And here, first, find the student whether
it is exist or not. For that we need to load
our student model find by ID store the result in
variable c student. If there is no
student with the ID, then we will simply return. Invalid student status,
fail and message like student not for the status 44 not four. If there is any student, then Student student. Database. Then set. Status success message student, delete successfully. I stay the score, use it. Go to Postman and
create a new request. Delete student and our
method name, delete. And our AP endpoint, Aplas here we need to pass
our student ID, which is two. First, I'm going to give a invalid student ID to check whether our valation
is working or not, Clicken student not form. Our valdN is working fine. Now I'm going to delete
the data of ID two. Further here I am passing
the ID as two ClickNd. We got status success student
deleted successfully. Go to get all student API and here we got
only one response. All right. In this section, we have
successfully created our very basic API for the student registration
process and from there, we can learn about how
to retrieve data from API by using G method and how to create data and how to
validate the request data we have learned about how to
get a single data from API and also we edit functionality
through our API, and also we have learned
about how to delete the student through API. Thank you. See you
on next lecture.
16. Class Wrap Up: Hello, everyone. Welcome
to this lecture. Let me walk through what we have done so far
in this section. We have created a new
APA resource controller, which is student APA controller, and in APA routes, we have defined our resource
route as APA resource, and we have created model five under models
folder app models. This is our Model
five student PHB. And here we have make all
the fields are fillable. And also we have created
migration table for this model, which is this one. And by using this, we have created code operations, which is create, read,
update, and delete. And also we have tested our
API in Postman API client. And now it's time to push our code to the Github for that. First, we need to check
the status status. These are the fives
has been modified. Git R. Next, Git message as basic API. Enter Gig. Go Gita. And as you can see,
our latest amid has been successfully pushed
to our Github prepostering. Thank you. See you next lecture.
17. Conclusion: Hello all. First of all, I would like to thank you and congratulate on
finishing this class. Let's see what we have
done in this class so far. I hope you have learned
how to install composer, which is PHP
dependency and how to install agon for a local
server for Laval project, and you have installed VS code for the code editor and
you have learned how to successfully install Lal on a local server and how
the file structure is defined in aaalPject also you have learned to create a
simple API card operations. I hope you have gained some valuable knowledge
from this class. If you like this class, please feel free to
leave your feedback. Thank you. See you
on my next class.