General Flashcards
What are HTTP methods?
HTTP methods are a set of standardized request methods used to indicate the desired action to be performed on a specific resource.
CRUD PGPD
CREATE => POST
READ => GET
UPDATE => PUT/PATCH
DESTROY => DELETE
GET
Used to retrieve data from the server. It’s a safe method, meaning it doesn’t have side effects and doesn’t change the state of the resource. It should only fetch data.
POST
Used to submit data to the server to create a new resource. It’s not idempotent, which means making the same request multiple times might result in different outcomes.
PUT
Used to update an existing resource or create a new resource if it doesn’t exist. It’s idempotent, so making the same request repeatedly has the same effect as making it once.
PATCH
Used to apply partial modifications to a resource. Unlike PUT, which updates an entire resource, PATCH only updates parts of a resource.
DELETE
As the name suggests, it’s used to delete a specified resource. It should be idempotent, meaning repeated calls to delete the same resource should have the same effect as a single call.
HEAD
Similar to the GET method, but it only retrieves the headers of a resource, not the actual data. This is useful when you want to check if a resource exists or to get metadata about a resource without downloading the entire content.
OPTIONS
Describes the communication options for the target resource. It returns the HTTP methods that the server supports for a specific URL
CONNECT
Primarily used in a proxy server environment. It establishes a network connection for use with HTTP/1.1.
TRACE
Performs a diagnostic loop-back test along the request path. It’s used for debugging purposes.
What does POST and PUT do, and what are their differences?
POST is primarily used to create a new resource. Making the same POST request multiple times can result in different outcomes.
PUT is used to update an existing resource or create a resource if it doesn’t already exist. Making the same PUT request repeatedly will have the same effect as making it once.
What does an HTTP request contain?
An HTTP request is a structured message comprising a request line, headers, and optionally, a body.
It is a message sent by the client to the server to fetch a resource, submit data, or perform other operations
What does a request - request line contain?
This is the first line in the HTTP request and consists of:
a. HTTP Method (or Verb): Indicates the desired action to be performed on the resource.
(e.g., GET, POST, PUT, DELETE).
b. Request URI (or URL): Specifies the path to the resource on the server.
c. HTTP Version: Indicates the version of HTTP being used (e.g., HTTP/1.1).
What does a request header contain?
These provide meta-information about the request. They are categorized into:
a. General Headers: These headers are present in both request and response messages but are not directly associated with the data in the message body (e.g., Cache-Control, Connection).
b. Request Headers: Provide additional information about the resource to be fetched or about the client (e.g., Accept, Host, User-Agent).
c. Entity Headers: Provide information about the body of the resource, like its length or type (e.g., Content-Type, Content-Length).
What does a request body (or payload) contain?
This is optional and contains data that needs to be sent to the server. For instance, data submitted through an HTML form using the POST method will be sent in the request body.
Is it possible to make a post request via get? Why or Why not?
No, you cannot make a POST request via GET.
A GET request is designed to retrieve data without causing side-effects, while a POST request is used to submit data to a server, potentially causing a change in the server’s state.
Making the same GET request multiple times should yield the same result without causing any side effects, while it does not with a POST.
Explain data transmission for GET vs POST.
In a GET request, data is appended to the URL as query parameters. There’s a length limit to URLs, which varies depending on browsers and servers, but is generally much shorter than the amount of data you can send in a POST request body. If you tried to send a large amount of data via GET, you could exceed this limit
Explain security for a GET vs POST request.
Data sent in a GET request’s URL can be logged by web servers, cached, or seen in browser history. Sensitive data, like passwords or personal information, should not be sent this way.
POST requests keep data in the request body, providing a layer of obscurity
What is the maximum size of a URL?
The maximum size of a URL is not defined by the HTTP protocol itself. About 2048 characters.
Most modern web browsers have a URL length limit of around 2,000 to 4,000 characters