Typed error handling in an Axum handler
▲ 0 r/rust

Typed error handling in an Axum handler

An Axum route extracts typed params, validates input, queries the database, and maps every failure to an HTTP response through one error enum.

Three takeaways

  1. A single error enum implementing IntoResponse centralizes how every failure becomes an HTTP status and body.
  2. Implementing From lets the `?` operator convert library errors into your domain error automatically.
  3. Destructuring extractors in the function signature pulls typed request data straight into named locals.
highlit.co
u/Environmental-Yak328 — 16 hours ago
▲ 0 r/PHP

Bulk-inserting users with batched PDO upserts

Chunk a large array into batches and upsert each with a single prepared multi-row INSERT.

Three takeaways

  1. Chunking huge datasets keeps each SQL statement within safe placeholder and packet limits.
  2. A single multi-row INSERT is far faster than one query per record.
  3. ON DUPLICATE KEY UPDATE turns an insert into an idempotent upsert against unique keys.
highlit.co
u/Environmental-Yak328 — 3 days ago
▲ 2 r/nestjs

A rate-limiting guard in NestJS

A custom guard reads per-route metadata and tracks request counts in memory to throttle callers.

Three takeaways

  1. Guards can pair with a custom decorator so per-route config travels as metadata read via the Reflector.
  2. A fixed-window counter needs only a count and an expiry timestamp per key to enforce limits.
  3. Throwing HttpException from a guard lets you return rich responses like a 429 with retryAfter.
highlit.co
u/Environmental-Yak328 — 3 days ago
▲ 2 r/photos

Misty autumn avenue of trees — landscape photo critique (8.1/10) · ShutterClick

A classic tree-tunnel avenue rendered with atmosphere and colour that genuinely reward the viewer's eye. The converging trunks pull the gaze to a misty vanishing point, and the autumn palette is handled with restraint rather than oversaturated. The low camera position over the leaf-strewn road is the single best decision here, grounding the frame and adding foreground weight. What holds it back most is the bright, near-blown centre where the mist meets the sky — that hotspot competes with the tunnel's pull. A touch more foreground sharpness and slightly recovered highlights would tip this from very good to excellent.

What would elevate it:

  1. Focusing near the hyperfocal distance at f/11 would carry the foreground leaves into sharpness while keeping the misty distance crisp.
  2. Recovering the near-blown central mist in post, or bracketing on capture, would preserve tone in the tunnel's brightest core.
  3. A little added contrast and clarity on the foreground road would strengthen it as an anchor against the luminous middle.
shutterclick.com
u/Environmental-Yak328 — 4 days ago
▲ 0 r/golang

A panic-recovery middleware in Gin

A Gin middleware that recovers from panics, logs them with structured context, and tells broken connections apart from real server errors.

Three takeaways

  1. Recovery middleware turns a panic anywhere in the handler chain into a controlled HTTP response instead of a crashed server.
  2. Broken-pipe errors mean the client already left, so there's no point returning a status - logging a warning is enough.
  3. Attaching request context like method, path, and request ID to every log entry makes production panics traceable.
highlit.co
u/Environmental-Yak328 — 4 days ago

Handling Stripe webhooks in FastAPI

A FastAPI endpoint that verifies Stripe's signature, then routes each event type to the right billing action.

Three takeaways

  1. Always verify a webhook's signature against a shared secret before trusting its contents.
  2. Read the raw request body for signature checks — parsed JSON won't match the signed bytes.
  3. Return 200 quickly and delegate the actual work so the provider considers the event delivered.
highlit.co
u/Environmental-Yak328 — 4 days ago
▲ 13 r/rust

Configuring CORS on an Axum Router

How to build an Axum router that applies a tuned CORS policy across its JSON API routes.

Three takeaways

  1. CORS layer must explicitly whitelist origins, methods, and headers rather than defaulting to permissive.
  2. Tower middleware applied with .layer wraps every route on the router uniformly.
  3. allow_credentials(true) requires a concrete origin - wildcards are rejected by browsers when credentials are sent.
highlit.co
u/Environmental-Yak328 — 5 days ago
▲ 0 r/rails+1 crossposts

Atomic money transfers with Rails transactions

A service object moves funds between two accounts atomically using row locks and a database transaction.

highlit.co
u/Environmental-Yak328 — 6 days ago
▲ 1 r/laraveltutorials+1 crossposts

How Eloquent observers hook lifecycle events in Laravel

An OrderObserver runs side effects at each stage of a model's life — creating, created, updated, deleting, and restored.

highlit.co
u/Environmental-Yak328 — 6 days ago
▲ 6 r/rails+1 crossposts

Live-updating comments with Turbo in Rails A Comment model pushes its own creates, updates, and deletes to subscribers over Turbo Streams.

highlit.co
u/Environmental-Yak328 — 7 days ago