schepotin/laravel-api

This package is abandoned and no longer maintained. No replacement package was suggested.

Laravel API

v5.7.0 2018-09-29 11:02 UTC

README

Build Status

Laravel API

Install

Install package:

composer require schepotin/laravel-api

Run command:

php artisan laravel-api:publish --api

Run migrations:

php artisan migrate

Boilerplate for Vue

php artisan laravel-api:publish --vue
npm install
npm run dev

Eslint

npm run eslint

API

Register:

request:

fetch('/api/v1/register', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8',
  },
  body: "name=John&email=johndoe@gmail.com&password=qwerty&password_confirmation=qwerty",
})
.then((response) => response.json())
.then((data) => {
  console.log(data);
});

response:

{
  "status": 1,
  "token": "yQZKTMgpB9wmX3seCH1XKrHyq62YQXijvnoAkFsHXmNcuv5SRhiTuWqbdsIP"
}

Login:

request:

fetch('/api/v1/login', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8',
  },
  body: "email=johndoe@gmail.com&password=123456",
})
.then((response) => response.json())
.then((data) => {
  console.log(data);
});

response:

{
  "status": 1,
  "token": "yQZKTMgpB9wmX3seCH1XKrHyq62YQXijvnoAkFsHXmNcuv5SRhiTuWqbdsIP"
}

Password reset:

request:

fetch('/api/v1/password/email', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8',
  },
  body: "email=johndoe@gmail.com",
})
.then((response) => response.json())
.then((data) => {
  console.log(data);
});

response:

{
  "status": 1,
  "data": {
    "message": "passwords.sent"
  }
}

request:

fetch('/api/v1/reset/password', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8',
  },
  body: "email=johndoe@gmail.com&password=qwerty&password_confirmation=qwerty&token=2b8db1c9655ed1dcf1752867b652774e48e890e2709daa992f271df5d787a8ce",
})
.then((response) => response.json())
.then((data) => {
  console.log(data);
});

response:

{
  "status": 1,
  "data": {
    "message": "passwords.reset"
  }
}

Get current logged user

request:

fetch('/api/v1/user/current', {
  method: 'GET',
  headers: {
    'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8',
    Authorization: 'Bearer yQZKTMgpB9wmX3seCH1XKrHyq62YQXijvnoAkFsHXmNcuv5SRhiTuWqbdsIP',
  },
})
.then((response) => response.json())
.then((data) => {
  console.log(data);
});

response:

{
  "status": 1,
  "data": {
    "id": 1,
    "name": "John",
    "email": "johndoe@gmail.com",
    "created_at": "2017-09-23 12:26:44",
    "updated_at": "2017-09-23 12:26:44"
  }
}