[[oktatas:web:back-end_framework:leaf|< Leaf]]
====== Leaf útválasztás ======
* **Szerző:** Sallai András
* Copyright (c) 2024, Sallai András
* Licenc: [[https://creativecommons.org/licenses/by-sa/4.0/|CC BY-SA 4.0]]
* Web: https://szit.hu
===== Első útvonal =====
//...
app()->get('/', function () {
response()->json(['msg' => 'műkszik']);
});
HTTP kliensbe:
* localhost:5500
app()->get('/msg', function() {
response()->json(['msg' => 'üdv']);
});
HTTP kliensbe:
* localhost:5500/msg
Tesztelés HTTPie klienssel:
http localhost:5500/msg
===== POST metódus =====
app()->post('/msg', function() {
response()->json(['msg' => 'üdv']);
});
Tesztelés HTTPie klienssel:
http post localhost:5500/msg
app()->post('employees', function() {
$name = request()->get('name');
response()->json(['name' => $name]);
});
Tesztelés HTTPie klienssel:
http post localhost:5500/employees name="Béla"
===== A PUT metódus =====
app()->put('employees/{id}', function() {
$name = request()->get('name');
response()->json(['name' => $name]);
});
Tesztelés HTTPie klienssel:
http put localhost:5500/employees/23 name="Béla"
===== A DELETE metódus =====
app()->delete('employees/{id}', function($id) {
response()->json(['for_delete' => $id]);
});
Tesztelés HTTPie klienssel:
http delete localhost:5500/employees/23
===== Erőforrásútvonalak =====
app()->resource('/employees', 'EmployeeController');
app()->run();
Olyan mintha ezt írtam volna:
app()->match('GET|HEAD', '/employees', "$controller@index");
app()->post('/employees', "$controller@store");
app()->match('GET|HEAD', '/employees/create', "$controller@create");
app()->match('POST|DELETE', '/employees/{id}/delete', "$controller@destroy");
app()->match('POST|PUT|PATCH', '/employees/{id}/edit', "$controller@update");
app()->match('GET|HEAD', '/employees/{id}/edit', "$controller@edit");
app()->match('GET|HEAD', '/employees/{id}', "$controller@show");
app()->run();
Dokumentáció:
* https://leafphp.dev/docs/routing/#resource-routes (2024)