Naar hoofdinhoud
← πŸ“„ HTML & the platformΒ·Module A3 Β· Les 1
OpdrachtBuild a login form: <form action='/api/login' method='post'> containing <input name='email' type='email'>, <input name='password' type='password'>, <button type='submit'>Log in</button>.

<form action method>: het verzoek dat uw backend ontvangt

75 XP8 min
Theorie

Three attributes shape the HTTP request

<form action="/api/signup" method="post" enctype="application/x-www-form-urlencoded">
  <input name="email" type="email" />
  <input name="password" type="password" />
  <button type="submit">Sign up</button>
</form>
  • `action` β€” where the form POSTs. Relative or absolute URL. Defaults to the current page.
  • `method` β€” get (default, params in URL) or post (body). For mutations, use post. For searches, use get.
  • `enctype` β€” only matters for POST:

- application/x-www-form-urlencoded (default) β€” email=anna%40example.com&password=…

- multipart/form-data β€” required when one or more inputs are <input type="file">

- text/plain β€” never use this, it's only for debugging

What FastAPI sees

For <form method="post"><input name="email" value="anna@example.com"></form>, your FastAPI endpoint:

@app.post("/api/signup")
async def signup(email: str = Form()):
    return {"got": email}

The name="email" is the Pydantic field name. If you change name="user_email" on the input, FastAPI's Form(alias="user_email") is what catches it.

GET vs POST visibility

get puts data in the URL (/search?q=python) β€” bookmarkable, sharable, in browser history. post puts data in the body β€” invisible in URL, not in history, not bookmarked. Passwords ALWAYS POST.

πŸ”’

Registreer om te beginnen met coderen

Theorie is voor iedereen. De editor, live preview en check ontgrendelen met een 7-daagse gratis proefperiode β€” kaart vereist, opzegbaar.

Registreren β€” gratis proef β†’

De eerste 10 lessen in elke track zijn gratis. Geen kaart nodig.

← VorigeVolgende les β†’

EΓ©n Python- of web-tip per dag β€” per e-mail

Kort, met de hand geschreven, geen spam. Met één klik afmelden.