Getting started
AJAX and JSON
Send forms with fetch from any framework, get JSON back, and show your own success and error messages.
The endpoint accepts three kinds of body and allows requests from any website (CORS is open), so you can send forms from the browser without a server of your own.
| Body | Use it for |
|---|---|
application/x-www-form-urlencoded |
Plain HTML forms (the browser's default) |
multipart/form-data |
new FormData(form), and any form with files |
application/json |
Data you build yourself in code |
To get JSON back instead of a redirect, send an Accept: application/json header. A JSON body gets a JSON answer automatically.
Send the form as it is
FormData picks up every named input, including the hidden access key and honeypot, and works with file inputs too. Don't set a Content-Type header yourself: the browser adds the right one.
const form = document.querySelector('#contact')
const status = document.querySelector('#status')
form.addEventListener('submit', async (event) => {
event.preventDefault()
const button = form.querySelector('button')
button.disabled = true
status.textContent = 'Sending…'
try {
const res = await fetch('https://lazyform-api.xvelopers.com/submit', {
method: 'POST',
headers: { Accept: 'application/json' },
body: new FormData(form),
})
const result = await res.json()
if (result.success) {
form.reset()
status.textContent = 'Thanks! We got your message.'
} else {
status.textContent = result.error.message
}
} catch {
status.textContent = 'Could not send. Check your connection and try again.'
} finally {
button.disabled = false
}
})Send JSON
await fetch('https://lazyform-api.xvelopers.com/submit', {
method: 'POST',
headers: { 'Content-Type': 'application/json', Accept: 'application/json' },
body: JSON.stringify({
access_key: 'YOUR_ACCESS_KEY',
subject: 'New signup',
email: 'ada@example.com',
plan: 'Pro',
}),
})Values are stored as text. Nested objects aren't flattened, so keep the body one level deep.
The response
Success is { "success": true, "message": "Submission received.", "id": "sub_…" }. Failures are { "success": false, "error": { "code", "message" } } with a 4xx status. Every code is listed in responses and errors.
From a server
You can also send submissions from your own server, a serverless function or a script, for example a Next.js server action. It's the same request.
curl -X POST https://lazyform-api.xvelopers.com/submit \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-d '{"access_key":"YOUR_ACCESS_KEY","name":"Ada","message":"Sent from curl"}'Requests from a server don't come from a browser page, so they have no page address. If you turned on Allowed websites for the form, they'll be refused with domain_not_allowed. Use a separate form for server-side sending.
Libraries
- The
lazyformnpm package wraps all of this, with a React hook. See SDK. - Want a ready-made form with no code at all? Use the drop-in widget.