Skip to main content
Syllabus
On this page

HTTP Methods & Messages (Basics for Forms/APIs)

Badar KhalilUpdated September 27, 2026 2 min read

HTTP Methods & Messages (Basics for Forms/APIs)

Understanding HTTP methods is essential for anyone working with HTML forms or building API-driven web apps. This guide covers the core HTTP methods — GET, POST, PUT, PATCH, DELETE — and explains how HTTP request and response messages are structured.

What Is HTTP?

HTTP (HyperText Transfer Protocol) is the foundation of data exchange on the web. Every time a browser loads a page, submits a form, or calls an API, it sends an HTTP request and receives an HTTP response back from the server.

1. Common HTTP Methods

MethodPurpose
GETRetrieves data from the server without changing it; used for loading pages and fetching resources
POSTSends new data to the server, commonly used for form submissions and creating records
PUTReplaces an existing resource entirely with new data
PATCHPartially updates an existing resource
DELETERemoves a resource from the server
HEADSame as GET but returns only headers, no body
OPTIONSAsks the server which methods/headers are allowed for a resource

2. HTTP Methods in HTML Forms

The <form> element's method attribute controls whether form data is sent via GET (appended to the URL) or POST (sent in the request body). Forms only natively support GET and POST — other methods like PUT/DELETE require JavaScript.

3. Anatomy of an HTTP Request

PartDescription
Request LineContains the method, path, and HTTP version (e.g. GET /users HTTP/1.1)
HeadersKey-value pairs with metadata like Content-Type, Authorization
BodyThe actual data sent, used with POST/PUT/PATCH requests

4. Anatomy of an HTTP Response

PartDescription
Status LineContains the HTTP version and status code (e.g. HTTP/1.1 200 OK)
HeadersMetadata about the response like Content-Type, Cache-Control
BodyThe actual returned content — HTML, JSON, images, etc.

5. Common HTTP Status Codes

CodeMeaning
200 OKRequest succeeded
201 CreatedResource successfully created (common after POST)
301/302Redirect to another URL
400 Bad RequestServer couldn't understand the request
401 UnauthorizedAuthentication required
404 Not FoundRequested resource doesn't exist
500 Internal Server ErrorSomething went wrong on the server

6. HTTP Methods in APIs (Fetch Example)

Modern APIs rely heavily on these HTTP methods to perform CRUD operations (Create, Read, Update, Delete) using JavaScript's fetch() function or libraries like Axios.

Try It Yourself

Explore the live code examples below to see HTTP methods used in real forms and API calls.

Try it Yourself HTML
Output

Press Run to execute.

Try it Yourself JAVASCRIPT
Output

Press Run to execute.

Try it Yourself JAVASCRIPT
Output

Press Run to execute.

Exercise: Send a PUT RequestJAVASCRIPT

Write a fetch() call that sends a PUT request to 'https://api.example.com/users/10' updating the user's name to 'Sarah'. Log the response as JSON.

Try it Yourself JAVASCRIPT
Output

Press Run to execute.

Show expected output
A fetch call configured with method: 'PUT' and a JSON body containing the updated name.

This is a self-check — compare your result with the expected output above.

Was this page helpful?