DEV Community

Amanda Jayathilaka
Amanda Jayathilaka

Posted on

Designing API Responses and Errors

Consistent responses make integrations easier. Return JPG bytes for successful conversions. Use an appropriate content type. Set attachment headers when downloads are intended. Document whether metadata is preserved.

Invalid requests should receive clear status codes. Unsupported formats can return HTTP 415. Missing files can return HTTP 400. Oversized requests can return HTTP 413. Unexpected server failures should return HTTP 500. Avoid returning stack traces to clients.

Error messages should explain corrective actions. Logs can contain additional diagnostic information. Never log uploaded image contents unnecessarily. Avoid including sensitive filenames in public responses. Request identifiers help connect errors with server logs.

For asynchronous processing, return a job identifier. Clients can poll a documented status endpoint. Completed jobs can provide temporary download links. Expiration policies should be explicit.

This is a example AVIF to JPG converter for beginners.

Top comments (0)