Install package:
composer require schepotin/laravel-api
Run command:
php artisan laravel-api:publish --api
Run migrations:
php artisan migrate
php artisan laravel-api:publish --vue
npm install
npm run dev
npm run eslint
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"
}
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"
}
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"
}
}
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"
}
}