Building a JSON API in plain PHP
Në shqip: API me JSON në PHP të thjeshtë
ShpjegimiSQ
Për një API të thjeshtë: vendos header('Content-Type: application/json'), lexo trupin me file_get_contents('php://input'), dhe kthe përgjigjen me echo json_encode($te_dhenat).
EnglishEN
For a simple API: set header('Content-Type: application/json'), read the body with file_get_contents('php://input'), and return the response with echo json_encode($data).
Si ta mendosh
Si një sportel që flet vetëm në gjuhën JSON.
Lexoje në anglisht
Like a counter that speaks only JSON.
Shembull kodiphp
header('Content-Type: application/json');
$hyrja = json_decode(file_get_contents('php://input'), true);
echo json_encode(['ok' => true, 'emri' => $hyrja['emri'] ?? null]);