Skip to content

nduagoziem/gadgets-hub-api

Repository files navigation

GADGETS HUB E-COMMERCE API

An API for a brand that deals on all kinds of gadgets. Built with the Laravel Framework.

Table of Contents

Installation and Setup

Clone the repository:

git clone https://github.com/nduagoziem/laravel-ecommerce-api
cd laravel-ecommerce-api

Install dependencies:

composer install
npm install

Set 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 dev

Authentication

Registration - Post Request

ENDPOINT

"/customer/register"

REQUEST

{
  "name": "John Doe",
  "email": "john@example.com",
  "password": "password123",
}

RESPONSE

{
  "success": true,
  "message": "Your account was created successfully."
}

STATUS

201

Login - Post Request

ENDPOINT

"/customer/login"

REQUEST

{
  "email": "john@example.com",
  "password": "password123",
}

RESPONSE

{
  "success": true,
  "message": "Login successful."
}

STATUS

200

Logged In Customer - Get Request

ENDPOINT

"/customer"

RESPONSE

{
  "success": true,
  "message": 
  [
    "name": "John Doe",
    "email": "john@gmail.com",
  ]
}

STATUS

200

Logout - Post Request

ENDPOINT

"/customer/logout"

RESPONSE

{
  "message": "Logged out."
}

STATUS

200

Cart

You must have an account and be logged in before using the cart feature.

Add to Cart - Post Request

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

200

Show Cart - Get Request

ENDPOINT

"/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

200

Update Cart - Patch Request

ENDPOINT

"/cart/update"

REQUEST

{
  "name": "Digital HD Camera",
  "productId": 44,
  "quantity": 102,
}

Remove from cart - Post Request

ENDPOINT

"/cart/remove"

REQUEST

{
  "name": "Pink Headset",
  "productId": 6,
}

RESPONSE

{
  "success": true,
  "message": "Removed from cart."
}

STATUS

200

Estimated Total Price - Get Request

ENDPOINT

"/cart/total"

RESPONSE

{
  "message": 20000.00
}

STATUS

200

Gadgets

Phones - Get Request

ENDPOINT

"/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": "&laquo; Previous",
          "active": false
      },
      {
          "url": "https://mywebsite.com/api/phones?page=1",
          "label": "1",
          "active": true
      },
      {
          "url": null,
          "label": "Next &raquo;",
          "active": false
      }
  ],
  "path": "https://mywebsite.com/api/phones",
  "per_page": 16,
  "to": 1,
  "total": 1
  }
}

STATUS

200

Computers - Get Request

ENDPOINT

"/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": "&laquo; Previous",
          "active": false
      },
      {
          "url": "https://mywebsite.com/api/pcs?page=1",
          "label": "1",
          "active": true
      },
      {
          "url": null,
          "label": "Next &raquo;",
          "active": false
      }
  ],
  "path": "https://mywebsite.com/api/pcs",
  "per_page": 16,
  "to": 1,
  "total": 1
  }
}

STATUS

200

Tablets - Get Request

ENDPOINT

"/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": "&laquo; Previous",
          "active": false
      },
      {
          "url": "https://mywebsite.com/api/tablets?page=1",
          "label": "1",
          "active": true
      },
      {
          "url": null,
          "label": "Next &raquo;",
          "active": false
      }
  ],
  "path": "https://mywebsite.com/api/tablets",
  "per_page": 16,
  "to": 1,
  "total": 1
  }
}

STATUS

200

Accessories - Get Request

ENDPOINT

"/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": "&laquo; Previous",
          "active": false
      },
      {
          "url": "https://mywebsite.com/api/accessories?page=1",
          "label": "1",
          "active": true
      },
      {
          "url": null,
          "label": "Next &raquo;",
          "active": false
      }
  ],
  "path": "https://mywebsite.com/api/accessories",
  "per_page": 16,
  "to": 1,
  "total": 1
  }
}

STATUS

200

Order

Order and Pay - Post Request

ENDPOINT

"/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

About

A Demo API for a brand that deals on all kinds of gadgets. Built with the Laravel Framework. You can also view the frontend repo here - https://github.com/nduagoziem/gadgets-hub-client

Resources

Stars

Watchers

Forks

Contributors

Languages