echo json_encode($products); } else { if ($http_method == "GET" && $param != null) { $product = ProductsDB::get(["id" => $param]); if ($product != null) { $product["uri"] = "http://" . $server_addr . $script_uri . "/izdelki/" . $product["id"]; echo json_encode($product); } else { returnError(404, "No entry for id: " . $param); } } else { if ($http_method == "POST" && $param == null) { $filteredInput = filter_input_array(INPUT_POST, $rules); $product = array_filter($filteredInput); try { $id = ProductsDB::insert($product); http_response_code(201); header("Location: http://{$server_addr}" . "{$script_uri}/izdelki/{$id}"); } catch (Exception $exc) { echo returnError(400, $exc->getMessage()); } } else { if ($http_method == "PUT" && $param != null) { // update $inputParams = null; parse_str(file_get_contents("php://input"), $inputParams); $filteredInput = filter_var_array($inputParams, $rules); $filteredInput["id"] = $param; $product = array_filter($filteredInput); //var_dump($product); try {