0% found this document useful (0 votes)
28 views

Laravel e-commerce API documentation

Uploaded by

maaz tajammul
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
28 views

Laravel e-commerce API documentation

Uploaded by

maaz tajammul
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 10

KARYANA E- Made by

Maaajammul
COMMERCE API
REST API for E-Commerce platform with admin panel integration.
#BuiltWithLaravel
Introduction
Welcome to the E-commerce API User Guide. This API is designed to
help developers integrate powerful e-commerce functionalities into
their applications. Built using Laravel, the API provides secure, scalable,
and efficient ways to manage products, orders, users, and more.

Key Features:
 User registration and authentication
 Secure API with token-based authentication
Getting Started
Installation:
To start using the E-commerce API, clone the repository and set up
the environment:
git clone https://github.com/Maaz0313/laravel-react-
ecom-api.git
cd laravel-react-ecom-api
composer install cp .env.example .env
php artisan key:generate

Prerequisites:
 PHP 8.2+
 MySQL 8+
 Composer 2.x
 Node.js & npm (for frontend assets if needed)

API Authentication:
The API uses Laravel Sanctum for authentication. To set it up, run:
php artisan migrate
php artisan serve

To authenticate, use the /api/login endpoint to receive a


token. Include this token in the Authorization header for
subsequent requests.
Endpoints Overview
Here is a brief overview of some important endpoints.
Method Endpoint Description
POST /api/register Register a new user.
POST /api /verify-otp Verifies user email by
OTP.
POST /api /resend-otp Resends OTP email.
POST /api/logout Logs out a user.
POST /api/login Logs in a user.
GET /api/user Fetches user info.
Detailed API Reference
Authentication Endpoints:
Register a User
 POST /api/register
 Request Body:
{
"name": "John Doe",
"email": "[email protected]",
"password": "password123",
"password_confirmation": "password123"
}
 Response:
{
"success": true,
"message": "Registered successfully. Please verify
your email by entering the OTP sent to your email.
Please use same browser for registration and
verification."
}

Verify Email
 POST /api/verify-otp
 Request Body:
{
"otp": "Your OTP"
}
 Response:
{
"success": true,
"message": " Email verified successfully."
}

Resend OTP Email


 POST /api/resend-otp
 Request Body:
{
"email": "Your email"
}
 Response:
{
"success": true,
"message": " OTP resent. Please check your email."
}

Login

 POST /api/login
 Request Body:
{
"email": "[email protected]",
"password": "password123"
}

 Response:
{
"token": "your-api-token"
}

Logout

 POST /api/logout
 Request Body:
none

 Response:
{
'message' => 'Successfully logged out.'
}

User

 POST /api/user
 Request Body:
Authorization: Bearer {your-access-token}
Accept: application/json
 Response:
{
"id": 1,
"name": "John Doe",
"email": "[email protected]",
"email_verified_at": "2023-11-09T10:00:00.000000Z",
"created_at": "2023-01-01T12:00:00.000000Z",
"updated_at": "2023-11-09T12:00:00.000000Z"
}

Error Handling
All errors follow a consistent format:
{
"success": false,
"message": "Invalid credentials",
"errors": {
"email": ["The email field is required."]
}
}

Error Code Description


400 Bad Request
401 Unauthorized
404 Resource Not Found
500 Internal Server Error
Best Practices
 Always use HTTPS for API requests.
 Implement rate limiting to avoid abuse.
 Use environment variables for sensitive data.
 Regularly update dependencies to patch vulnerabilities.
Troubleshooting
Issue: Unable to connect to the database.
 Ensure .env file has correct DB credentials.
 Run php artisan config:cache after updating .env.

You might also like