This endpoint receives contact form submissions, validates input with Zod, and returns a JSON response. It does not require authentication by default.
- Endpoint:
POST /api/contact - File Location:
src/app/api/contact/route.ts
Parameters
Sender’s first name. Minimum length: 2.
Sender’s last name. Minimum length: 2.
Valid email address for reply.
Company or organization name. Minimum length: 2.
Message content. Minimum length: 10.
Request/Response
Example Request
Example Response (Success)
Example Response (Validation Error · 400)
Example Response (Server Error · 500)
How It Works
- Receives Data: The endpoint accepts a
POSTrequest with a JSON body containing the form data. - Validates Data: It uses a Zod schema to perform server-side validation. This is a crucial security step to ensure data integrity. If validation fails, it returns a
400 Bad Requesterror. - Processes Data: By default, the endpoint logs the validated data to the server console.
- Returns Response: On success, it returns a
200 OKresponse with a success message.
Customizing the Submission Logic
To make the contact form useful, you need to replace the defaultconsole.log action with your own business logic. A common use case is to send an email notification.
Example: Sending an Email with Resend
Here’s how you can modify the endpoint to send an email using Resend, a popular email service for React developers.Get API Key
Sign up for a Resend account and get your API key. Add it to your
.env.local file..env.local
Resend is optional and not bundled by default. This example shows how you can wire it if you need email notifications. For global route protection vs per‑route guards, see Routing & Middleware.