APIs Are Where Systems Start Talking

· Updated

A contact form looks simple until the browser loses the response. Did the request fail before reaching the server, or did the email provider accept it before the connection timed out? Sending again with a new identity can create a duplicate. Displaying success without evidence can hide a lost enquiry.

This portfolio’s contact workflow provides a concrete example of that boundary. The implementation separates input validation, spam verification, provider acceptance and what the interface can truthfully tell the visitor.

Validate before handing work to another service

The server checks the request origin, payload size and allowed fields before sending an email. It verifies the spam-protection token server-side rather than trusting the browser’s state. A malformed request or failed verification should stop before the provider is called.

Field mapping is explicit. The visitor’s address is used for replies; the recipient remains a server-side configuration value. This keeps a public enquiry endpoint from becoming an arbitrary email-sending interface.

A timeout is an uncertain outcome

The browser assigns an identifier to a submission and retains it with the same details when an attempt is uncertain. The server derives the provider idempotency key from that identifier. Retrying unchanged details can therefore refer to the same operation rather than create a new one.

A retry still needs a fresh spam-verification token. That token proves the new request is allowed to proceed; it is not the identity of the email operation. Treating those two values as interchangeable would break either verification or deduplication.

The provider’s deduplication window is finite. The server rejects old submission identifiers before that window expires. The interface also prevents edits to an uncertain attempt, so a retry does not silently change the meaning of an existing operation.

Name the result accurately

The API returns an accepted result only after receiving a provider response containing an identifier. That confirms provider acceptance, not delivery into the recipient’s inbox. A pending operation, invalid input, rate limit and unavailable provider need distinct handling so the visitor has a useful next step.

On an uncertain failure, the interface retains the entered details and explains how to retry. It does not convert a network timeout into an automatic claim that nothing was sent.

Test the failure boundary

The automated tests exercise rejected origins, invalid input, escaped email content, unchanged retries, concurrent attempts and a simulated timeout after provider acceptance. The latter checks that retrying does not trigger a second send in the mocked provider. Those tests verify application behaviour; they do not establish real-world inbox delivery.

The same distinction appears in financial corrections and retry validation: an HTTP response, a completed business action and what the user can see are related, but they are not the same event. A dependable integration makes those boundaries explicit.