Requests & Responses Flashcards
Define HTTP Request Methods
*HTTP defines several request methods that indicate the desired action to be performed on a resource.
*Common HTTP request methods include GET, POST, PUT, DELETE, PATCH, HEAD, and OPTIONS.
*Each method has a specific purpose, such as retrieving data (GET), submitting data (POST), updating data (PUT, PATCH), or deleting data (DELETE).
Define HTTP Headers
*HTTP headers are additional pieces of information sent between the client and server along with the request or response.
* Headers provide metadata about the request or response, such as content type, content length, caching directives, authentication credentials, etc.
* Examples of common headers include Content-Type, Content-Length, Accept, User-Agent, etc.
Define HTTP Status Codes
- HTTP status codes are three-digit numbers returned by a server in response to a client’s request.
- They indicate the success, failure, or other status of the request.
- Examples include 200 (OK), 404 (Not Found), 500 (Internal Server Error), etc.
Status codes are grouped into categories like 1xx (Informational), 2xx (Success), 3xx (Redirection), 4xx (Client Error), and 5xx (Server Error).
Expand on HTTP Request Structure
- An HTTP request consists of a request line, headers, an optional body, and a blank line separating the headers and body.
- The request line includes the request method, URI, and HTTP version.
- Headers provide additional information about the request, and the body carries optional data (e.g., form data or JSON payload) for POST or PUT requests.
What is the HTTP Response Structure
- An HTTP response consists of a status line, headers, an optional body, and a blank line separating the headers and body.
- The status line includes the HTTP version, status code, and a brief status message.
- Headers provide metadata about the response, and the body contains the actual data returned by the server (e.g., HTML content, JSON data).
Elaborate on the GET Request Method
- The GET method is used to request data from a specified resource.
- It sends data in the URL’s query string, making it visible in the browser’s address bar.
- GET requests are idempotent, meaning they produce the same result regardless of how many times they are repeated.
How are path parameters defined in Django?
- Variables within the URL path that define specific resource identifiers.
- Example: ‘/users/{username}
What are the response codes for redirection?
- 301: Moved Permanently - Resource has been permanently moved to a new location
- 302: Found - Resource temporarily moved to a different location