Skip to content

MeghaGDev/laravel-product-api

Repository files navigation

Laravel Product API with Pagination and Cache

This project is a RESTful API built using Laravel. It demonstrates product management with CRUD operations, pagination, caching, factories, and seeders.

The project is designed to help understand backend API development and performance optimization using caching.

Features

  • Product CRUD API
  • Pagination support
  • API caching for faster responses
  • Database seeders
  • Model factories
  • RESTful API design
  • JSON responses

Tech Stack

  • Laravel
  • PHP
  • MySQL
  • REST API
  • Laravel Cache
  • Laravel Pagination

Installation

Clone the repository

git clone https://github.com/yourusername/laravel-product-api.git

Navigate to project folder

cd laravel-product-api

Install dependencies

composer install

Copy environment file

cp .env.example .env

Generate application key

php artisan key:generate

Configure database in .env file

Run migrations

php artisan migrate

Seed database

php artisan db:seed

Run the server

php artisan serve

API will run at

http://127.0.0.1:8000

API Endpoints

Get paginated products

GET /api/products?page=1

Create product

POST /api/products

Update product

PUT /api/products/{id}

Delete product

DELETE /api/products/{id}

Pagination

Products are returned in pages using Laravel pagination.

Example request

/api/products?page=2

Each page returns 10 products.

Caching

Product list responses are cached using Laravel Cache.

Cache key example

products_page_1

This improves API performance by reducing database queries.

Cache is cleared whenever a product is created, updated, or deleted.

Database Seeding

The project includes seeders and factories to generate sample data.

Run

php artisan db:seed

This will generate 100 sample products.

Learning Objectives

This project demonstrates:

  • REST API development
  • Pagination implementation
  • API caching strategy
  • Laravel factories and seeders
  • Backend performance optimization

Author

Backend practice project built for learning Laravel API development.

About

REST API built with Laravel featuring Product CRUD operations, pagination, caching, factories, and seeders for efficient data handling.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages