POST Requests and Sending Data

Learn to send data to servers using POST requests — the same mechanism behind form submissions, creating accounts, and posting content.

Step 1 of 6

GET vs. POST: Reading vs. Writing

So far, every fetch call we've made has been a GET request — asking the server to give us data. But the web is a two-way street. When you create an account, post a comment, submit a form, or upload a photo, your browser is sending data to the server. That's a POST request.

If you completed the Forms module, you've already seen this: when a form has method="POST", the browser sends the form data to the server. With fetch(), you can do the same thing — and more — entirely from JavaScript, without a form and without reloading the page.

The main HTTP methods you'll encounter:

  • GET — Read/retrieve data (the default for fetch())
  • POST — Create new data (new user, new post, new comment)
  • PUT — Replace existing data entirely
  • PATCH — Update part of existing data
  • DELETE — Remove data

Think of it this way: GET is like reading the menu at a restaurant — you're just looking at what's available. POST is like placing an order — you're sending information to the kitchen (the server) and asking them to create something new for you.
Learn more on MDN