Mod 7 Flashcards
When should we use an HTTP Get request?
When we type a URL in a browser, the browser sends an HTTP GET request to the server. GET requests should be used to read data from the server. The GET method is thus analogous to the Read/Retrieve operation among the CRUD operations. With a GET request, information is passed to the server via the URL path and the query string. While the HTTP specification does not prohibit sending a body with an HTTP GET request, sending a body with a GET request is not recommended at all.
When should we use an HTTP Post request?
The POST method sends data to the server in the body of the request. Many times POST is used when submitting forms. A prescribed use of the POST method is for creating a new resource, e.g., a new document in a database. This means if an HTTP request being sent to the server to perform a create operation, then the POST method should be used. The POST method thus corresponds to the Create operation among the CRUD operations.
When should an HTTP Put method be used?
While the POST method is used for create operations, the HTTP PUT method is used for update operations. A prescribed use of the PUT method is for HTTP requests in which a resource is completely replaced by the data in the HTTP request with the PUT method. For example, if we wanted to send an HTTP request to replace all the properties of a document to new values, then it would be an appropriate use case for the PUT method. The PUT method thus corresponds to the Update operation among the CRUD operations. Data is sent in the body of the request for HTTP requests that use the PUT method.
When should an HTTP Patch method be used?
The prescribed use of the PATCH method is for partial updates of a resource, unlike PUT which is used for completely replacing the resource. For example, if we want to send an HTTP request to update some, but not all, properties of a document, then it would be an appropriate use case for the PATCH method. The PATCH method thus also corresponds to the Update operation among the CRUD operations. Note support for the PATCH method is not universal and many web server support partial updates using the PUT method.
When should an HTTP Delete Method be used?
The prescribed use of the DELETE method is to delete a resource. For example, if we want to send an HTTP request to delete a document, then it would be an appropriate use case for the DELETE method. The DELETE method thus corresponds to the Delete operation among the CRUD operations.
When should the HTTP Head method be used?
The HEAD method is similar to GET in that it requests a resource for retrieval. However, the response to a request using the HEAD method does not include the resource, but only includes the status line and the HTTP response headers. This is used by clients, such as browsers, to determine if the resource in their cache is still fresh, or should they now issue a GET request for the resource
What is an endpoint?
The term endpoint is used for the combination of a URL and an HTTP method. Two requests that have the same URL, but different HTTP methods, are considered two different endpoints. In Express it is simple to define routes based on the combination of a URL and HTTP method
How does a browser or a server know how to interpret bytes that it is sent?
This information is conveyed by using values from a standard called Multipurpose Internet Mail Extensions or MIME type. This is used in the Content-Type header.
- The typical structure of a MIME type is of the form type/subtype, i.e., two strings separated by a /.
- The type indicates a general category. Example types include text or application and image.
- The subtype indicates the exact type of data within that category.
What is the accept header used for?
The Accept header is used in HTTP requests by a client to tell the server about the types of data the client can handle. In general, the value of the Accept header is one or more MIME types separated by commas.
Are you likely to encounter 100-199 response codes?
Status codes in this category indicate that the request was received and the server is continuing to process it. They are very uncommon and you are unlikely to encounter them.
What are the response codes in 200-299?
Status codes in this category indicate that the request was successfully processed by the server.
- 200: OK: The request succeeded and the response body has the needed information. The server will send this response code for successful requests in many cases, e.g., GET requests, DELETE and PUT requests if information about deleted/updated resources is being sent back in the body.
- 201: Created: The request succeeded and a new resource was created. Typically, a POST request will return 201 status code on success. Typically, the response with 201 status code includes the URL of the newly created resource in the response header Content-Location.
- 204: No content: The request succeeded. However, there is no content to return in the body. A typical use case is when the server has successfully processed a DELETE or PUT request, but there is no other information that the server is sending back beyond reporting the success of the request.
What is the general use of response codes in 300-399?
- The server sends back status codes in this category when the client needs to take additional action to complete the request.
- These codes are mostly used for URL redirection. A common example is http to https redirection.
What is the difference between a 301 and 302 response code?
- The 301 response code is sent when a resource has been permanently moved (like moving an http to https). The browser knows to always go to the new location, sent in the location header.
- The 302 response code is sent when a resource was found but a redirect was sent using the location header. This is common when you need a user to sign in at another page. The browser will not change the URI in future requests.
What is a 303 status code?
303: See Other: Server is redirecting to another resource whose URI is in the location header. For example, a resource was created and its URI is in the location header.
What is the 304 Status code?
304: Not Modified: The resource has not modified. Essentially the server is telling the client to use the cached copy of the resource.