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.