Sveltekit Form Endpoint

Sveltekit Form Endpoint has some breaking changes. Let's see what they are.

svelte logo

Want a Svelte site built?
Hire Me.

Sveltekit Form Endpoint

After merging this pull request there have been a few changes in Sveltekit Endpoints and how it works.

I did a video on Sveltekit contact form which uses an endpoint but some changes should be done to get it working.

Contact Form

<form action="/api/contact" method="POST">
  <label for=""
    >Email
    <input type="email" name="email" />
  </label>

  <label for="">
    Password
    <input type="password" name="password" />
  </label>

  <input type="submit" />
</form>

Endpoint /api/contact.js

export const post = async ({ request }) => {
  const body = await request.formData();
  const email = body.get("email");
  const password = body.get("password");

  return {
    body: {
      email,
    },
  };
};

Please make these corrections in the video below,

Let's discuss on Twitter

Copyrights © webjeda