1. What is HTTP/HTTPS?
- HTTP (HyperText Transfer Protocol): Protocol used for communication between web browsers and servers.
- HTTPS (HTTP Secure): Secure version of HTTP that uses encryption (SSL/TLS).
- Purpose: Transmit data (requests and responses) over the web.
2. Why are HTTP/HTTPS Methods Important?
- Define how data is sent to/from servers.
- Enable CRUD operations:
- Create
- Read
- Update
- Delete
3. HTTP Methods Overview
Method | Purpose | Common Use Cases |
---|---|---|
GET | Retrieve data | Fetch web pages, read records, search data. |
POST | Send data | Submit forms, upload files, create resources. |
PUT | Update/replace data | Update existing records, replace resources. |
DELETE | Remove data | Delete records or resources from a server. |
4. Detailed Explanation of Methods
a) GET
- Purpose: Retrieve data from the server.
- Characteristics:
- Sends data in the URL (query parameters).
- Idempotent: Multiple GET requests produce the same result.
- No body content in the request.
- Example:
GET /products?category=books HTTP/1.1
Host: www.example.com
- Use Case: Search products, fetch user profiles, retrieve blog posts.
b) POST
- Purpose: Send data to the server to create new resources.
- Characteristics:
- Data sent in the body of the request.
- Non-idempotent: Repeated POST requests can create duplicate resources.
- Example:
POST /register HTTP/1.1
Host: www.example.com
Content-Type: application/json
{
"username": "user123",
"password": "pass123"
}
- Use Case: User registration, file upload, form submission.
c) PUT
- Purpose: Update or replace existing data on the server.
- Characteristics:
- Sends data in the body of the request.
- Idempotent: Repeated PUT requests produce the same result.
- Example:
PUT /profile/123 HTTP/1.1
Host: www.example.com
Content-Type: application/json
{
"name": "John Doe",
"email": "john.doe@example.com"
}
- Use Case: Updating user profiles, replacing configurations.
d) DELETE
- Purpose: Remove resources from the server.
- Characteristics:
- No body content in most cases.
- Idempotent: Repeated DELETE requests produce the same result.
- Example:
DELETE /products/123 HTTP/1.1
Host: www.example.com
- Use Case: Deleting user accounts, removing files, clearing data.
5. Comparison Table
Feature | GET | POST | PUT | DELETE |
---|---|---|---|---|
Purpose | Retrieve data | Send/Create data | Update/Replace data | Remove data |
Idempotent | Yes | No | Yes | Yes |
Request Body | No | Yes | Yes | No |
Common Use | Read operations | Create resources | Update operations | Delete records |
HTTP response codes:
Category | Code | Name | Meaning (Simplified) |
---|---|---|---|
Success | 200 | OK | Request succeeded, and the server returned the requested data. |
201 | Created | A new resource has been successfully created. | |
202 | Accepted | Request accepted but not yet processed. | |
204 | No Content | Request succeeded, but there’s no content to return. | |
Redirection | 301 | Moved Permanently | Resource has permanently moved to a new URL. |
302 | Found (Temporary Redirect) | Resource temporarily resides at a different URL. | |
304 | Not Modified | Resource hasn’t changed since the last request. | |
Client Error | 400 | Bad Request | The request is invalid or malformed. |
401 | Unauthorized | Authentication is required or failed. | |
403 | Forbidden | The server understands the request but refuses to authorize it. | |
404 | Not Found | The resource could not be found on the server. | |
Server Error | 500 | Internal Server Error | A generic error occurred on the server. |
501 | Not Implemented | The server doesn’t support the requested functionality. | |
502 | Bad Gateway | The server received an invalid response from an upstream server. | |
503 | Service Unavailable | The server is temporarily unavailable (e.g., maintenance or overload). |
6. Quick Revision Points
- GET: Fetch data – No body, data in URL.
- POST: Send data – Non-idempotent, body used for input.
- PUT: Update/replace data – Idempotent, uses body for input.
- DELETE: Remove data – Idempotent, typically no body.
MCQ
What does HTTP stand for?
a) HyperText Transfer Protocol
b) HyperText Translation Protocol
c) HyperText Transformation Protocol
d) HyperText Transaction Protocol
Answer: a) HyperText Transfer Protocol
Which HTTP method is used to retrieve data from a server?
a) POST
b) GET
c) PUT
d) DELETE
Answer: b) GET
Which HTTP method is typically used to submit form data?
a) GET
b) POST
c) PUT
d) DELETE
Answer: b) POST
What is the main purpose of the PUT method in HTTP?
a) To retrieve data
b) To update or replace data
c) To create data
d) To delete data
Answer: b) To update or replace data
Which HTTP method is idempotent?
a) GET
b) PUT
c) DELETE
d) All of the above
Answer: d) All of the above
Which of the following is NOT a characteristic of the POST method?
a) Sends data in the body of the request
b) Non-idempotent
c) Used for updating existing resources
d) Can create new resources
Answer: c) Used for updating existing resources
What does the DELETE method do?
a) Removes resources from the server
b) Updates resources
c) Retrieves data
d) Submits data
Answer: a) Removes resources from the server
Which HTTP method is most suitable for creating new resources?
a) GET
b) POST
c) PUT
d) DELETE
Answer: b) POST
What is a key difference between GET and POST methods?
a) GET is used to delete data, POST is used to retrieve data
b) GET sends data in the URL, POST sends data in the body
c) POST is idempotent, GET is not
d) GET requires authentication, POST does not
Answer: b) GET sends data in the URL, POST sends data in the body
Which of the following HTTP methods is NOT idempotent?
a) GET
b) POST
c) PUT
d) DELETE
Answer: b) POST
In an HTTP request, where does the GET method send its parameters?
a) In the body of the request
b) In the URL as query parameters
c) In the headers
d) As an attachment
Answer: b) In the URL as query parameters
Which HTTP method is used to partially update a resource?
a) GET
b) POST
c) PATCH
d) PUT
Answer: c) PATCH
Which HTTP method replaces the resource entirely?
a) PATCH
b) POST
c) PUT
d) DELETE
Answer: c) PUT
What does HTTPS add to HTTP?
a) Increased bandwidth
b) Faster loading times
c) Security through encryption (SSL/TLS)
d) Reduced latency
Answer: c) Security through encryption (SSL/TLS)
Which HTTP method is used for deleting a resource, and is idempotent?
a) POST
b) PUT
c) DELETE
d) GET
Answer: c) DELETE
What status code is returned when a DELETE request is successful?
a) 200 OK
b) 204 No Content
c) 201 Created
d) 404 Not Found
Answer: b) 204 No Content
Which HTTP method is commonly used for API testing and fetching resources without any side effects?
a) POST
b) PUT
c) GET
d) DELETE
Answer: c) GET
What is the default port number for HTTPS?
a) 80
b) 443
c) 8080
d) 21
Answer: b) 443
Which HTTP method may lead to duplication of data if sent multiple times?
a) GET
b) PUT
c) POST
d) DELETE
Answer: c) POST
What is the typical use of the PUT method in RESTful APIs?
a) To delete data
b) To retrieve data
c) To create or update a resource
d) To secure data
Answer: c) To create or update a resource
What is the maximum length of a URL in a GET request?
a) 1024 characters
b) Unlimited
c) Limited by browser and server (usually 2048 characters)
d) 256 characters
Answer: c) Limited by browser and server (usually 2048 characters)
Which HTTP status code indicates a resource has been created successfully?
a) 200 OK
b) 201 Created
c) 202 Accepted
d) 404 Not Found
Answer: b) 201 Created
What does the Content-Type header indicate in a POST request?
a) The type of data being requested
b) The format of the data being sent in the body
c) The server’s IP address
d) The resource URL
Answer: b) The format of the data being sent in the body
Which HTTP method does not have a message body?
a) GET
b) POST
c) PUT
d) PATCH
Answer: a) GET
What is the primary advantage of HTTPS over HTTP?
a) Faster response times
b) Encrypted communication for better security
c) Reduced data usage
d) Automatic caching of resources
Answer: b) Encrypted communication for better security