How to build a REST API with Laravel


Laravel allows you to easily and quickly create RESTful APIs. This could be the backend of a frontend web app, a data source for a mobile app, or a service for other apps or APIs.

There are a lot of moving parts to coding a RESTful API, but Laravel makes it much easier. In this free course, you’ll learn everything you need to know to build RESTful APIs with Laravel.

What will you learn

  • define data models and seed database test data
  • handle basic GET requests
  • transform data from the database into a consistent and conventional JSON format
  • create flexible, reusable filter syntax for users to query and filter data
  • handle and validate POST, PUT and PATCH requests
  • implement bulk inserts to allow end users to quickly insert multiple entities with a single request
  • secure your API endpoints with Laravel Sanctum to authenticate and authorize requests

Who is this free course for?

  • complete beginners who want to become web developers
  • experienced developers who want to explore advanced topics
  • programming enthusiasts who love to learn something exciting

Follow, learn by doing

I encourage you aftake this course and you will learn everyone the most important features of Vue.js

To help, the Build a Rest API with Laravel Github repository contains the source code for each lesson and the completed example project that was built throughout the course.

1. introduction

Watch the video lesson [0:00:00] ↗

This course will teach you how to build a Rest API with Laravel. In this introductory lesson, you’ll take a look at the scope of the course.

2. To start

Project creation

Watch the video lesson [0:01:38] ↗

In this lesson, you will go over the things you will need to take in this course. Follow to set up your development environment and create your project.

Here is a short tutorial on how to set up your Laravel environment for Windows:

Database design and seeding

Watch the video lesson [0:7:36] ↗

In this lesson you will create the migrations, factories and seed data for our database.

3. Data provision

Version control and path definition

Watch the video lesson [0:19:22] ↗

Good web APIs are versioned, so you need to implement some kind of versioning. You will also configure the paths for the first version of the API.

Transform database data into JSON

Watch the video lesson [0:26:17] ↗

RESTful APIs typically provide data in JSON format using JSON naming conventions. In this lesson you will use Resource classes to transform our data into conventional JSON.

Data filtering

Watch the video lesson [0:35:48] ↗

You need to provide customers with the ability to filter results. In this lesson, you will implement a customer filter.

Filtering more data

Watch the video lesson [0:49:47] ↗

In this lesson, you generalize our filter functionality so that you can reuse it for any resource.

Including related data

Watch the video lesson [0:58:49] ↗

Sometimes it makes sense to include related data in your API results, but it should be a feature customers choose to opt into. You will implement it in this lesson.

4. Data manipulation

Creating resources with POST requests

Watch the video lesson [1:05:37] ↗

POST requests are for creating resources. In this lesson, you will handle POST requests to create customer resources.

See the Laravel documentation on built-in validation rules for more information.

Update with PUT and PATCH

Watch the video lesson [1:14:48] ↗

We update data using PUT and PATCH requests, and in this lesson, you’ll learn how to handle both types of requests.

Implementation of collective insertion

Watch the video lesson [1:22:51] ↗

Some resources must be entered in bulk. You will learn how to implement it in this lesson.

5. Authentication

Path protection with Sanctum

Watch the video lesson [1:33:41] ↗

Laravel 7 introduced Sanctum, a token authentication scheme for APIs and SPAs. It’s great, and you’ll be using it to create tokens in this lesson.

Learn more about Laravel Sanctum in the official docs.

Authorizing requests with token ability

Watch the video lesson [1:41:29] ↗

Sanctum allows us to assign abilities to tokens and it’s easy to authorize requests. However, there is one caveat that you will learn in this lesson.

Conclusion

Watch the video lesson [1:48:10] ↗

Laravel has the tools we need to build usable and scalable applications, including RESTful APIs. In fact, Laravel does a lot of hard things for us, making it a much more fun way to build software.

Find out more in the Journal Laravel Documentation or The Laravel Community Portal.

PHP Tutorial for Beginners – Complete Course | OVER 7 HOURS!

Learn the fundamentals of PHP and object-oriented programming in this free 7-hour PHP tutorial. Jeremy McPeak will help you learn PHP and use it to write web apps.




Source link

By LocalBizWebsiteDesign

Leave a Reply

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