Skip to content

smnafiz/laravel-sanctum-sample-api

Repository files navigation

Build Status Total Downloads Latest Stable Version License

About Project

API for mobile apps and other frontend apps built by Laravel and Sanctum. Just clone the repo and run the project you will get few sample apis for testing on your frontend.

Installing

  1. Clone the project
  2. run composer install
  3. run php artisan migrate
  4. run php artisan vendor:publish --provider="Laravel\Sanctum\SanctumServiceProvider"

Running

  1. run php artisan serve

Available Api

URL: /api/create

Method: POST

Request:

$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_URL => 'http://127.0.0.1:8000/api/create',
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => '',
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 0,
  CURLOPT_FOLLOWLOCATION => true,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => 'POST',
  CURLOPT_POSTFIELDS => array('name' => 'Smin','email' => 'sminrana1001@gmail.com','password' => '12345678')
));

$response = curl_exec($curl);

curl_close($curl);
echo $response;

Response:

{
    "success": true,
    "token": {
        "name": "TutsForWeb",
        "abilities": [
            "*"
        ],
        "tokenable_id": 9,
        "tokenable_type": "App\\Models\\User",
        "updated_at": "2021-04-17T11:00:48.000000Z",
        "created_at": "2021-04-17T11:00:48.000000Z",
        "id": 14
    }
}

URL: /api/login

Method: POST

Request:

$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_URL => 'http://127.0.0.1:8000/api/login',
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => '',
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 0,
  CURLOPT_FOLLOWLOCATION => true,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => 'POST',
  CURLOPT_POSTFIELDS => array('email' => 'sminrana1001@gmail.com','password' => '12345678'),
));

$response = curl_exec($curl);

curl_close($curl);
echo $response;

Response:

{
    "login": true,
    "token": "15|YLJIcanaEVeuyP82KqdKFSw8t3izgd9uAYqSmWvi",
    "data": {
        "id": 9,
        "name": "Smin",
        "email": "sminrana1001@gmail.com",
        "email_verified_at": null,
        "created_at": "2021-04-17T11:00:48.000000Z",
        "updated_at": "2021-04-17T11:00:48.000000Z"
    },
    "message": "Login successful"
}

URL: /api/user/cart (logged user shopping cart)

Method: GET

Request:

$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_URL => 'http://127.0.0.1:8000/api/user/cart',
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => '',
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 0,
  CURLOPT_FOLLOWLOCATION => true,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => 'GET',
  CURLOPT_HTTPHEADER => array(
    'Authorization: Bearer 9|jgItvy6W7AuqrnhtBm53yU8Bu3mMS9DiiClPqQHH'
  ),
));

$response = curl_exec($curl);

curl_close($curl);
echo $response;

Response:

[
    {
        "id": 1,
        "name": "Product 1",
        "price": 110.5
    },
    {
        "id": 2,
        "name": "Product 2",
        "price": 10.5
    }
]

URL: /api/products

Method: GET

Request:

$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_URL => 'http://127.0.0.1:8000/api/products',
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => '',
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 0,
  CURLOPT_FOLLOWLOCATION => true,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => 'GET',
));

$response = curl_exec($curl);

curl_close($curl);
echo $response;

Response:

[
    {
        "id": 1,
        "name": "Product 1",
        "price": 110.5
    },
    {
        "id": 2,
        "name": "Product 2",
        "price": 10.5
    },
    {
        "id": 3,
        "name": "Product 3",
        "price": 50
    }
]

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published