General Web Development Flashcards
What is the difference between REST and RPC?
REST - Representational state transfer
- Widely accepted set of guidelines for creating stateless, reliable web APIs.
- Models the various entities within the problem domain as resources, and uses HTTP verbs to represent transactions against these resources - POST to create, PUT to update, and GET to read. All of these verbs, invoked on the same URL
- REST: http://MyRestaurant:8080/Orders/Order?OrderNumber=asdf (POST: {Tacos object})
RPC - Remote Procedure Call
- you’re calling a different URL each time
- RPC: http://MyRestaurant:8080/Orders/PlaceOrder (POST: {Tacos object})
What is statelessness in REST?
- As per the REST (REpresentational “State” Transfer) architecture, the server does not store any state about the client session on the server-side. This restriction is called Statelessness.
- This restriction is called Statelessness. Each request from the client to the server must contain all of the necessary information to understand the request
- The application’s session state is therefore kept entirely on the client. The client is responsible for storing and handling the session related information on its own side.
https://restfulapi.net/statelessness/
What are some of the basic error responses from a web application
- Informational responses (100 – 199)
- Successful responses (200 – 299)
- Redirection messages (300 – 399)
- Client error responses (400 – 499)
- Server error responses (500 – 599)
- 100 Continue - This interim response indicates that the client should continue the request or ignore the response if the request is already finished.
- 200 OK - The request succeeded. The result meaning of “success” depends on the HTTP method
- 302 Found - This response code means that the URI of requested resource has been changed temporarily. Further changes in the URI might be made in the future. Therefore, this same URI should be used by the client in future requests.
- 400 Bad Request - The server cannot or will not process the request due to something that is perceived to be a client error (e.g., malformed request syntax, invalid request message framing, or deceptive request routing).
- 401 Unauthorized - Although the HTTP standard specifies “unauthorized”, semantically this response means “unauthenticated”. That is, the client must authenticate itself to get the requested response.
- 403 Forbidden - The client does not have access rights to the content; that is, it is unauthorized, so the server is refusing to give the requested resource. Unlike 401 Unauthorized, the client’s identity is known to the server.
- 404 Not Found - The server cannot find the requested resource. In the browser, this means the URL is not recognized. In an API, this can also mean that the endpoint is valid but the resource itself does not exist. Servers may also send this response instead of 403 Forbidden to hide the existence of a resource from an unauthorized client.
- 405 Method Not Allowed - The request method is known by the server but is not supported by the target resource. For example, an API may not allow calling DELETE to remove a resource.
- 500 Internal Server Error - The server has encountered a situation it does not know how to handle.
- 502 Bad Gateway - This error response means that the server, while working as a gateway to get a response needed to handle the request, got an invalid response.
- 503 Service Unavailable - The server is not ready to handle the request. Common causes are a server that is down for maintenance or that is overloaded.
- 504 Gateway Timeout - This error response is given when the server is acting as a gateway and cannot get a response in time.
What are the typical fields for a error response with REST APIs
type – a URI identifier that categorizes the error
title – a brief, human-readable message about the error
status – the HTTP response code (optional)
detail – a human-readable explanation of the error
instance – a URI that identifies the specific occurrence of the error
What is the difference between a GET and POST method?
The GET method is the method used by the browser to ask the server to send back a given resource: “Hey server, I want to get this resource.” In this case, the browser sends an empty body. Because the body is empty, if a form is sent using this method the data sent to the server is appended to the URL.
Since the GET method has been used, you’ll see the URL www.foo.com/?say=Hi&to=Mom appear in the browser address bar when you submit the form.
The data is appended to the URL as a series of name/value pairs. After the URL web address has ended, we include a question mark (?) followed by the name/value pairs, each one separated by an ampersand (&). In this case, we are passing two pieces of data to the server:
GET /?say=Hi&to=Mom HTTP/2.0 Host: foo.com
The POST method is a little different. It’s the method the browser uses to talk to the server when asking for a response that takes into account the data provided in the body of the HTTP request: “Hey server, take a look at this data and send me back an appropriate result.” If a form is sent using this method, the data is appended to the body of the HTTP request.
Let’s look at an example — this is the same form we looked at in the GET section above, but with the method attribute set to POST.
When the form is submitted using the POST method, you get no data appended to the URL, and the HTTP request looks like so, with the data included in the request body instead:
POST / HTTP/2.0 Host: foo.com Content-Type: application/x-www-form-urlencoded Content-Length: 13 say=Hi&to=Mom
What is meant by protocal?
A protocal is a set of rules that defines communication between to points.
*A protocol is a system of rules that define how data is exchanged within or between computers. Communications between devices require that the devices agree on the format of the data that is being exchanged. The set of rules that defines a format is called a protocol.
*
https://developer.mozilla.org/en-US/docs/Glossary/Protocol
What is TPC?
TCP (Transmission Control Protocol) is a network protocol that lets two hosts connect and exchange data streams.
TCP guarantees the delivery of data and packets in the same order as they were sent.
What is HTTP?
- Hypertext transfer protocal
- HTTP is a protocol for fetching resources such as HTML documents.
- It is the foundation of any data exchange on the Web and it is a client-server protocol, which means requests are initiated by the recipient, usually the Web browser, but not always.
- A complete document is reconstructed from the different sub-documents fetched, for instance, text, layout description, images, videos, scripts, and more
- Http is on the application layer.
- It is an application layer protocol that is sent over TCP, or over a TLS-encrypted TCP connection, though any reliable transport protocol could theoretically be used.
- Due to its extensibility, it is used to not only fetch hypertext documents, but also images and videos or to post content to servers, like with HTML form results. HTTP can also be used to fetch parts of documents to update Web pages on demand
Why is HTTP extensible?
HTTP headers make this protocol easy to extend and experiment with. New functionality can even be introduced by a simple agreement between a client and a server about a new header’s semantics.
What is meant by the statelessness of HTTP?
- HTTP is stateless: there is no link between two requests being successively carried out on the same connection.
- HTTP cookies allow the use of stateful sessions. Using header extensibility, HTTP Cookies are added to the workflow, allowing session creation on each HTTP request to share the same context, or the same state.
How does HTTP interact with connections and different versions of HTTP?
- A connection is controlled at the transport layer, and therefore fundamentally out of scope for HTTP.
- HTTP doesn’t require the underlying transport protocol to be connection-based; it only requires it to be reliable, or not lose messages (at minimum, presenting an error in such cases).
- Among the two most common transport protocols on the Internet, TCP is reliable and UDP isn’t. HTTP therefore relies on the TCP standard, which is connection-based.
- Before a client and server can exchange an HTTP request/response pair, they must establish a TCP connection, a process which requires several round-trips.
- The default behavior of HTTP/1.0 is to open a separate TCP connection for each HTTP request/response pair. This is less efficient than sharing a single TCP connection when multiple requests are sent in close succession.
- In order to mitigate this flaw, HTTP/1.1 introduced pipelining (which proved difficult to implement) and persistent connections: the underlying TCP connection can be partially controlled using the Connection header.
- HTTP/2 went a step further by multiplexing messages over a single connection, helping keep the connection warm and more efficient.
What is the difference and uses of UDP and TCP?
Both TCP and UDP are protocols used for sending bits of data—known as packets—over the Internet. Both protocols build on top of the IP protocol. In other words, whether you’re sending a packet via TCP or UDP, that packet is sent to an IP address. These packets are treated similarly, as they’re forwarded from your computer to intermediary routers and on to the destination.
UDP is similar to TCP but does away with error checking and retries. UDP is used for streaming and online gaming where latency is more important than having all the data.
TCP is the most commonly used protocol on the Internet.
Whether an application uses TCP or UDP is up to its developer, and the choice depends on what an application needs. Most apps need the error-correction and robustness of TCP, but some applications need the speed and reduced overhead of UDP. If you fire up a network analysis tool like Wireshark, you can see the different types of packets traveling back and forth.
What are the steps in the HTTP flow?
- Open a TCP connection: The TCP connection is used to send a request, or several, and receive an answer. The client may open a new connection, reuse an existing connection, or open several TCP connections to the servers.
- Send an HTTP message: HTTP messages (before HTTP/2) are human-readable. With HTTP/2, these simple messages are encapsulated in frames, making them impossible to read directly, but the principle remains the same. For example:
- Read the response sent by the server, such as:
- Close or reuse the connection for further requests.
https://developer.mozilla.org/en-US/docs/Web/HTTP/Overview
What does an HTTP request typically contain?
- An HTTP method, usually a verb like GET, POST, or a noun like OPTIONS or HEAD that defines the operation the client wants to perform. Typically, a client wants to fetch a resource (using GET) or post the value of an HTML form (using POST), though more operations may be needed in other cases.
- The path of the resource to fetch; the URL of the resource stripped from elements that are obvious from the context, for example without the protocol (http://), the domain (here, developer.mozilla.org), or the TCP port (here, 80).
- The version of the HTTP protocol.
- Optional headers that convey additional information for the servers.
- A body, for some methods like POST, similar to those in responses, which contain the resource sent.
What does the HTTP response typically contain?
- The version of the HTTP protocol they follow.
- A status code, indicating if the request was successful or not, and why.
- A status message, a non-authoritative short description of the status code.
- HTTP headers, like those for requests.
- Optionally, a body containing the fetched resource