[[oktatas:web:back-end_framework:laravel:laravel_rest_api|< Laravel API]]
====== Laravel API - JavaScript kliens ======
* **Szerző:** Sallai András
* Copyright (c) Sallai András, 2022
* Licenc: [[https://creativecommons.org/licenses/by-sa/4.0/|CC Attribution-Share Alike 4.0 International]]
* Web: https://szit.hu
===== JavaScript =====
==== fetch() ====
const token = '3|7eBr5iAUPgqQz3lxIFgC72Yh3ERO76g1MyuHNOGD';
const url = 'http://localhost:8080/api/employees/search/László';
fetch(url, {
headers: {
Authorization: `token ${token}`
}
})
.then(res => res.json())
.then(json => console.log(json));
===== jQuery $.ajax() =====
const url = 'http://localhost:8000/api/employees';
const token = '3|7eBr5iAUPgqQz3lxIFgC72Yh3ERO76g1MyuHNOGD';
$.ajax({
url: url,
type: 'get',
contentType: 'application/json',
headers: {
'Authorization': `Bearer ${token}`
},
success: function (result) {
console.log(result);
},
error: function (error) {
console.log(error);
}
});