---
title: 'How to Build a REST API with Laravel'
source: 'https://youtube.com/watch?v=bRRH2qXcX7w'
video_id: 'bRRH2qXcX7w'
date: 2026-06-15
duration_sec: 0
---

# How to Build a REST API with Laravel

> Source: [How to Build a REST API with Laravel](https://youtube.com/watch?v=bRRH2qXcX7w)

## Summary

In this course, Jonathan, a full stack web developer and instructor at Treehouse, teaches how to build a REST API using Laravel, a popular PHP framework. The video covers the basics of REST, including statelessness and the difference between application and resource state, and guides through setting up a Laravel project, creating a database, and preparing a welcome view.

### Key Points

- **Course Introduction** [0:05] — Jonathan introduces himself as a full stack web developer and instructor at Treehouse, and states the goal of building a REST API with Laravel.
- **REST API vs Web Application** [0:20] — Both take requests and return responses, but web apps return HTML while REST APIs commonly return JSON or XML.
- **What is REST?** [0:44] — REST stands for Representational State Transfer, an architectural style introduced by Roy Fielding in 2000, with six guiding constraints.
- **Statelessness Constraint** [1:08] — The most important constraint: requests must contain all necessary information, and no state context is stored on the server, only on the client.
- **Application State vs Resource State** [1:26] — Resource state is the state of data on the server; application state is everything needed to keep the app running, stored in server memory.
- **Prerequisites** [2:06] — Familiarity with setting up a Laravel project with Composer and basic understanding of REST APIs using Postman is required.
- **Habit of Reading Laravel Documentation** [2:39] — Develop a habit of reading Laravel documentation regularly, and ensure you select the correct Laravel version.
- **Value of Building REST APIs** [3:06] — REST APIs are valuable for PHP developers as front-end frameworks and mobile apps need backend servers to respond to requests.
- **Course Project Overview** [3:35] — Build a REST API that allows submitting favorite books and authors, with CRUD operations, a common use case for APIs and SaaS applications.
- **Installing Laravel with Composer** [4:11] — Install Laravel with Composer, create a new project in the desired directory, e.g., 'laravel_apps' on the desktop.
- **Composer Update Note** [4:42] — Existing Laravel projects with dependencies need 'composer update' to install dependencies, but new projects do not.
- **Navigating to Project and Opening in VS Code** [5:17] — Use 'cd Laravel_rest_api/' then open in Visual Studio Code with 'code .'.
- **Serving Laravel Application** [5:37] — Use 'php artisan serve' to run the Laravel app, and open a new terminal for other commands.
- **Creating Database and Updating .env** [5:59] — Create a database, user, and password, then add them to the .env file. Some Mac users may need DB_SOCKET.
- **Testing Database Connection** [6:33] — Run 'php artisan migrate' to test the database connection and credentials.
- **Updating Welcome View** [6:49] — Edit the welcome view in resources/views to add links for README, authors, books, and a JSON formatter Chrome extension.
- **Summary of Progress** [8:34] — Installed Laravel, added database credentials, tested migration, and updated the welcome view. Next: delete default migrations and create models and migrations.

### Conclusion

By the end of this course, you will have built a fully functional REST API with Laravel that supports CRUD operations for books and authors, a valuable skill for any PHP developer.

## Transcript

[MUSIC]
Hi, I'm Jonathan,
a full stack web developer and
instructor here at Treehouse.
In this course, we're going to
build a REST API with Laravel,
one of the most popular
PHP frameworks today.
Even if you've never built an API,
the concept is very similar
to web applications.
They both take in a request and
return a response.
The critical difference
is how they respond.
Web applications return an HTML format.
While REST APIs most commonly return
a JSON format, and sometimes XML.
So what is REST, exactly?
REST is an acronym that stands for
Representational State Transfer.
An architectural style first
represented by Roy Fielding in 2000.
Check the teachers notes below to
learn more about Roy Fielding and
the six guiding constraints for
all REST APIs.
The most important constraint
to remember is statelessness.
Requests from clients to the server
must contain all of the information
necessary to understand the request.
And cannot store any state context
on the server, only on the client.
It's also important to remember that
application state is not
the same as resource state.
Resource state, in the context of REST,
is the state of some data represented
on the server at any point in time.
Application state, on the other hand,
is everything necessary to keep
your application running,
which is stored in the server's memory,
and is faster than storing and
retrieving information from a database.
For example,
to identify incoming requests,
such as creating, modifying,
or deleting a resource.
Before taking this course, you should
be familiar with setting up a Laravel
project with composer and have a basic
understanding of rest API's using postman.
If you need to brush up on Laravel,
Composer, REST APIs, or
Postman, check out
the teachers notes below.
As always,
you can use the controls to speed up or
slow down this video, and
the captions are moveable.
So feel free to move the closed
captions to suit your needs.
Finally, try to develop a solid habit of
reading the Laravel
documentation regularly.
And be sure to select the correct
Laravel version as well.
Laravel has excellent documentation.
And if you're not sure what version
of Laravel you're working with,
navigate to your project
directory in the terminal and
type php artisan --version to find out.
Building a REST API is
a valuable skill that any PHP
developer should have in their
wheelhouse of development skills.
Front-end frameworks are becoming
more popular every day, and
they will all need a backend server
responding to their requests.
Mobile applications have become part
of everyday life around the world.
And yet, they all need to
communicate with a database or
some infrastructure, most commonly REST.
In this course,
we'll build a REST API with Laravel
that allows you to submit your
favorite books and authors.
The REST API we're building from scratch
can return a list of books with authors,
and also allows you to submit,
update, and delete books and authors.
This aggregating of information
is a common use case for APIs,
as well as SaaS applications,
short for software as a service,
such as TurboTax, or Spotify.
Let's get started.
To get started, you'll need to
install Laravel with Composer,
then create a new Laravel project in
your preferred working directory.
For demonstration purposes,
I'll use laravel_apps in
the desktop directory, like this.
Open the terminal and
navigate to the desktop using the cd
Desktop/laravel_apps/ command,
then use the following command to create a
Laravel project using Composer like this.
While Composer installs Laravel, it's
worth noting that any existing Laravel
project that uses dependencies, will
need to run the Composer update command
to install any dependencies used
by the existing application.
Since this is a new project, we don't need
to use the Composer update command, but
you will eventually need to use
it when working with teams, or
when you want to run an existing
Laravel application using dependencies.
To learn more about Composer update, and
Laravel mix,
check out the teacher's notes below.
Next, let's navigate to our
new Laravel project using
cd Laravel_rest_api/ then
use the following command
to open our new Laravel
project in Visual Studio code.
Finally, let's review our Laravel app
by using the following command in
the integrated terminal like this.
Great job.
We have our Laravel application up and
running.
Before we continue,
let's open a new terminal so
we can continue serving our Laravel
application using the first terminal.
Next, create a database, user, and
password which will add to
the .env file like this
Note that some Mac OS
users may need to use
an additional database
variable named DB_SOCKET.
Remember, if you need to review how
to create a database, user, and
password, or
you're getting errors such as db-errors or
max length errors, be sure to
check the teacher's notes below.
To test our new Laravel application and
the database credentials we entered,
simply type php artisan
migrate in the terminal.
Great job,
we successfully migrated our database.
This next step is optional, but
i like to use the default welcome view for
testing so I can see what our API looks
like in the browser as we add new routes.
Let's edit the welcome view located
in the resources/views directory,
or download the project files and
simply paste the welcome blade like this.
First, change the titles on line 7 and
84 to build
a Laravel REST API Next,
let's add the following links.
Replace the # sign with the URL for
your README if you have one for
this project on GitHub Next,
we're going to add the author's link.
The author's link uses the built in
env function to access the app URL.
Cool.
Next, we're going to add
the books link like this.
The books link also uses the built in
env function to access the app URL.
Finally, let's add a Chrome
extension link like this.
The handy Chrome extension named
json-formatter displays JSON
in a more human readable format.
Let's take a look at
the updated welcome view.
Nice job, we have a landing page,
or welcome view,
showing off our application with a README,
our author, and
book routes, and a link to the JSON
formatter chrome extension.
We're off to a great start.
We've installed Laravel using Composer,
added our database credentials to the env
file, and tested our database
connection using the artisan command,
php artisan migrate.
We even updated the welcome view
to make a useful landing page.
In the next section, we're going to
delete our default migrations and
use artisan to create our projects
database models and migrations.
See you there.
