The objective of the present study was to develop a simple, sensitive and cost-effective sample pretreatment technique to extract and determine caffeine in different samples of beverage as well as urine. An anodized aluminum bar was electrochemically prepared and employed as nanoporous substrate for in-situ growth of crystals of the zeolitic imidazole framework-67 (ZIF-67). The above-mentioned sorbent, too, was applied as a stir bar sorptive extraction (SBSE) device along with HPLC-UV. Under predetermined experimental condition, the detection limit of the aimed method was 0.05 μg L−1 in beverages, and it was 0.1 μg L−1 in urine samples. Moreover, the linear dynamic range was 0.2–200 μg L−1 for beverages, and it was 0.5–200 μg L−1 for urine samples, too. The inter-day RSDs (10 μg L−1) were 5.3% and 5.7% respectively, and they were 5.8% and 6.1% for intra-day RSDs (10 μg L-1) in beverages and urine samples. Bar to bar reproducibility for three prepared bars equaled 6.2%. The applicability of the SBSE-HPLC-UV was investigated by determining caffeine in different samples of beverage and urine. The final range of obtained spiking recoveries was from 91.2 to 104%.