Rules Hub
Code Ruleset
Rule priority, scope & exceptions
Use this to align rules with the senior-level structure (P0/P1/P2, scope, exceptions/tradeoffs).
Keep HTTP GET reads separate from resource creation
Use GET to retrieve a resource. Put explicit import, creation or reactivation behind a separate mutation operation rather than creating a business record when a read misses.
Bad example
| 1 | app.get('/records/:id', async (req, res) => { |
| 2 | const record = await store.find(req.params.id) ?? await store.import(req.params.id); |
| 3 | res.json(record); |
| 4 | }); |
Explanation (EN)
Reading a missing record creates a new business record. Retries or prefetching can trigger unintended imports.
Objašnjenje (HR)
Čitanje nepostojećeg zapisa stvara novi poslovni zapis. Ponovni pokušaji i prefetch mogu izazvati neželjeni import.
Good example
| 1 | app.get('/records/:id', async (req, res) => { |
| 2 | const record = await store.find(req.params.id); |
| 3 | if (!record) return res.sendStatus(404); |
| 4 | return res.json(record); |
| 5 | }); |
| 6 | app.post('/imports', async (req, res) => { |
| 7 | const record = await store.import(req.body.sourceId); |
| 8 | res.status(201).json(record); |
| 9 | }); |
Explanation (EN)
Retrieval and explicit creation use separate operations.
Objašnjenje (HR)
Dohvat i izričito stvaranje koriste odvojene operacije.
Notes (EN)
Apply to user-visible business state changes in HTTP handlers. Verify the actual route and source before claiming that a GET mutates state. RFC 9110 section 9.2.1 defines safe methods.
Bilješke (HR)
Primjenjuje se na promjene poslovnog stanja vidljive korisnicima. Prije tvrdnje da GET mijenja stanje provjeri stvarnu rutu i izvor.
Exceptions / Tradeoffs (EN)
Incidental access logging, metrics and cache population may occur during GET. Authorization, validation and idempotency for mutation routes remain separate requirements.
Iznimke / Tradeoffi (HR)
Bilježenje pristupa, metrike i popunjavanje cachea dopušteni su tijekom GET-a. Autorizacija, validacija i idempotentnost mutation ruta zasebni su zahtjevi.