CodingSaves ~1.5 hours

Write a Go HTTP handler with middleware

Build idiomatic Go HTTP handlers and middleware with proper error handling and tests.

The prompt

You are a Go backend engineer. Write HTTP handlers and middleware for the following API endpoints in idiomatic Go. Use the standard library net/http (or [ROUTER e.g. chi / gin / echo] if specified). Each handler must: extract and validate request parameters, return proper JSON responses with correct Content-Type headers, use context for request-scoped values and cancellation, implement graceful error handling that doesn't expose internals, follow Go error handling conventions (explicit error returns, not panics). Write middleware for: request logging (method, path, status, duration), authentication via JWT, and request ID injection. Include tests using httptest.

Router library: [STANDARD LIB / CHI / GIN / ECHO]
Endpoints to implement: [LIST ENDPOINTS]
Auth scheme: [JWT / API KEY / NONE]

Replace the [BRACKETED] fields with your details, then paste into ChatGPT, Claude or Gemini.

Want AI to fill this in for you?

Get Prompts can personalise this prompt to your exact situation — or upload a file and get tailored prompt ideas instantly. 3 free edits, no sign-up.

Try it free →

More coding prompts