An API for a brand that deals on all kinds of gadgets. Built with the Laravel Framework.
Clone the repository:
git clone https://github.com/nduagoziem/laravel-ecommerce-api
cd laravel-ecommerce-apiInstall dependencies:
composer install
npm installSet up environment variables:
Create a .env file in the root directory and add the necessary environment variables. Use .env.example as a guide.
Run the application:
php artisan migrate
php artisan serve
npm run devENDPOINT
"/customer/register"REQUEST
{
"name": "John Doe",
"email": "john@example.com",
"password": "password123",
}RESPONSE
{
"success": true,
"message": "Your account was created successfully."
}STATUS
201ENDPOINT
"/customer/login"REQUEST
{
"email": "john@example.com",
"password": "password123",
}
RESPONSE
{
"success": true,
"message": "Login successful."
}STATUS
200ENDPOINT
"/customer"RESPONSE
{
"success": true,
"message":
[
"name": "John Doe",
"email": "john@gmail.com",
]
}STATUS
200ENDPOINT
"/customer/logout"RESPONSE
{
"message": "Logged out."
}STATUS
200You must have an account and be logged in before using the cart feature.
ENDPOINT
"/cart/add"REQUEST
{
"name": "Brand New PS5 Gaming Setup",
"imagePath": "https://yourimagepath.example.com",
"productId": 247 // Primary key of the product in the DB. Of course this is re-validated.
}RESPONSE
{
"success": true,
"message": "Added to Cart."
}STATUS
200ENDPOINT
"/cart/show"RESPONSE
{
"cart_id": 1,
"created_at": "2025-09-24T10:27:44.000000Z",
"id": 63,
"image_path": "https://yourimagepath.example.com",
"in_stock": 1,
"name": "Digital HD Camera",
"price": "20000.00",
"product_id": 1,
"quantity": 1,
"updated_at": "2025-09-24T10:27:44.000000Z"
}STATUS
200ENDPOINT
"/cart/update"REQUEST
{
"name": "Digital HD Camera",
"productId": 44,
"quantity": 102,
}ENDPOINT
"/cart/remove"REQUEST
{
"name": "Pink Headset",
"productId": 6,
}RESPONSE
{
"success": true,
"message": "Removed from cart."
}STATUS
200ENDPOINT
"/cart/total"RESPONSE
{
"message": 20000.00
}STATUS
200ENDPOINT
"/api/phones"PARAMETERS
fields - name, brand, price, tags, stock, description, hashid, id.
Example - "/api/phones?fields[]=name&fields[]=price&fields[]=brand"
hashid - arandomstring
Example - "/api/phones?hashid=arandomstring"
brand - brand of a phone e.g tecno, itel etc.
Example - "/api/phones?brand=vivo"
search - a text e.g brand new samsung galaxy s24
Example - "/api/phones?search=brand new samsung galaxy s24"
per_page - How many gadgets or products per page. Default value is 16.
Example - "/api/phones?per_page=20"
RESPONSE
{
"data": [
{
"id": 1,
"hashid": "arandomstring",
"name": "Tecno Spark 10 Pro",
"price": 50000,
"brand": "tecno",
"tags": "black",
"stock": 20,
"description": "<p>Brand New Phone</p>",
"media": [
{
"id": "a-random-string",
"url": "https://yourimageurlorpath.example.com"
}
]
}
],
"links": {
"first": "https://mywebsite.com/api/phones?page=1",
"last": "https://mywebsite.com/api/phones?page=1",
"prev": null,
"next": null
},
"meta": {
"current_page": 1,
"from": 1,
"last_page": 1,
"links": [
{
"url": null,
"label": "« Previous",
"active": false
},
{
"url": "https://mywebsite.com/api/phones?page=1",
"label": "1",
"active": true
},
{
"url": null,
"label": "Next »",
"active": false
}
],
"path": "https://mywebsite.com/api/phones",
"per_page": 16,
"to": 1,
"total": 1
}
}STATUS
200ENDPOINT
"/api/pcs"PARAMETERS
fields - name, brand, price, tags, stock, description, hashid, id.
Example - "/api/pcs?fields[]=name&fields[]=price&fields[]=brand"
hashid - arandomstring
Example - "/api/pcs?hashid=arandomstring"
brand - brand of a phone e.g dell, hp etc.
Example - "/api/pcs?brand=hp"
search - a text e.g Apple MacBook M4 Pro.
Example - "/api/pcs?search=Apple MacBook M4 Pro."
per_page - How many gadgets or products per page. Default value is 16.
Example - "/api/pcs?per_page=20"
RESPONSE
{
"data": [
{
"id": 1,
"hashid": "arandomstring",
"name": "Dell Latitude E7440 Windows 10 Pro.",
"price": 50000,
"brand": "tecno",
"tags": "black",
"stock": 20,
"description": "<p>Brand New Laptop</p>",
"media": [
{
"id": "a-random-string",
"url": "https://yourimageurlorpath.example.com"
}
]
}
],
"links": {
"first": "https://mywebsite.com/api/pcs?page=1",
"last": "https://mywebsite.com/api/pcs?page=1",
"prev": null,
"next": null
},
"meta": {
"current_page": 1,
"from": 1,
"last_page": 1,
"links": [
{
"url": null,
"label": "« Previous",
"active": false
},
{
"url": "https://mywebsite.com/api/pcs?page=1",
"label": "1",
"active": true
},
{
"url": null,
"label": "Next »",
"active": false
}
],
"path": "https://mywebsite.com/api/pcs",
"per_page": 16,
"to": 1,
"total": 1
}
}STATUS
200ENDPOINT
"/api/tablets"PARAMETERS
fields - name, brand, price, tags, stock, description, hashid, id.
Example - "/api/tablets?fields[]=name&fields[]=price&fields[]=brand"
hashid - arandomstring
Example - "/api/tablets?hashid=arandomstring"
brand - brand of a phone e.g ipad, dell tablets etc.
Example - "/api/tablets?brand=dell"
search - a text e.g Brand New Dell Tablets
Example - "/api/tablets?search=brand new dell tablets"
per_page - How many gadgets or products per page. Default value is 16.
Example - "/api/tablets?per_page=26"
RESPONSE
{
"data": [
{
"id": 1,
"hashid": "arandomstring",
"name": "iPad 26",
"price": 50000,
"brand": "ipad",
"tags": "silver",
"stock": 88,
"description": "<p>Brand New iPad</p>",
"media": [
{
"id": "a-random-string",
"url": "https://yourimageurlorpath.example.com"
}
]
}
],
"links": {
"first": "https://mywebsite.com/api/tablets?page=1",
"last": "https://mywebsite.com/api/tablets?page=1",
"prev": null,
"next": null
},
"meta": {
"current_page": 1,
"from": 1,
"last_page": 1,
"links": [
{
"url": null,
"label": "« Previous",
"active": false
},
{
"url": "https://mywebsite.com/api/tablets?page=1",
"label": "1",
"active": true
},
{
"url": null,
"label": "Next »",
"active": false
}
],
"path": "https://mywebsite.com/api/tablets",
"per_page": 16,
"to": 1,
"total": 1
}
}STATUS
200ENDPOINT
"/api/accessories"PARAMETERS
fields - name, price, tags, stock, description, hashid, id.
Example - "/api/accessories?fields[]=name&fields[]=price"
hashid - arandomstring
Example - "/api/accessories?hashid=arandomstring"
search - a text e.g Brand New PS5 Console.
Example - "/api/accessories?search=brand new ps5 console."
per_page - How many gadgets or products per page. Default value is 16.
Example - "/api/accessories?per_page=26"
RESPONSE
{
"data": [
{
"id": 1,
"hashid": "arandomstring",
"name": "iPad 26",
"price": 50000,
"tags": "white, new, ps5",
"stock": 88,
"description": "<p>Brand New PS5</p>",
"media": [
{
"id": "a-random-string",
"url": "https://yourimageurlorpath.example.com"
}
]
}
],
"links": {
"first": "https://mywebsite.com/api/accessories?page=1",
"last": "https://mywebsite.com/api/accessories?page=1",
"prev": null,
"next": null
},
"meta": {
"current_page": 1,
"from": 1,
"last_page": 1,
"links": [
{
"url": null,
"label": "« Previous",
"active": false
},
{
"url": "https://mywebsite.com/api/accessories?page=1",
"label": "1",
"active": true
},
{
"url": null,
"label": "Next »",
"active": false
}
],
"path": "https://mywebsite.com/api/accessories",
"per_page": 16,
"to": 1,
"total": 1
}
}STATUS
200ENDPOINT
"/customer/order"REQUEST
{
"first_name": "John", // Required
"last_name": "Doe", // Required
"email": "john@gmail.com", // Required
"phone_number": "08023456789", // Required - Phone Number should be a string.
"address": "42nd Japa Street.", // Required
"country": "Nigeria", // Required
"apartment_name": "", //Optional
"state": "Oyo", // Required
"postal_code": , // Optional
"city": "My City", // Required
}RESPONSE
{
"success": true,
"message": "https://redirect-url-for-payment"
}STATUS
200