General Web Development Flashcards

1
Q

What is the difference between REST and RPC?

A

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})
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is statelessness in REST?

A
  • 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/
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What are some of the basic error responses from a web application

A
  • 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.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What are the typical fields for a error response with REST APIs

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is the difference between a GET and POST method?

A

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
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is meant by protocal?

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is TPC?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is HTTP?

A
  1. Hypertext transfer protocal
  2. HTTP is a protocol for fetching resources such as HTML documents.
  3. 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.
  4. A complete document is reconstructed from the different sub-documents fetched, for instance, text, layout description, images, videos, scripts, and more
  5. Http is on the application layer.
  6. 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.
  7. 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
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Why is HTTP extensible?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is meant by the statelessness of HTTP?

A
  • 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 well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

How does HTTP interact with connections and different versions of HTTP?

A
  1. A connection is controlled at the transport layer, and therefore fundamentally out of scope for HTTP.
  2. 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).
  3. 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.
  4. 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.
  5. 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.
  6. 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.
  7. HTTP/2 went a step further by multiplexing messages over a single connection, helping keep the connection warm and more efficient.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is the difference and uses of UDP and TCP?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What are the steps in the HTTP flow?

A
  1. 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.
  2. 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:
  3. Read the response sent by the server, such as:
  4. Close or reuse the connection for further requests.
    https://developer.mozilla.org/en-US/docs/Web/HTTP/Overview
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What does an HTTP request typically contain?

A
  • 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.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What does the HTTP response typically contain?

A
  1. The version of the HTTP protocol they follow.
  2. A status code, indicating if the request was successful or not, and why.
  3. A status message, a non-authoritative short description of the status code.
  4. HTTP headers, like those for requests.
  5. Optionally, a body containing the fetched resource
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

How does TCP work?

A
  1. When you request a web page in your browser, your computer sends TCP packets to the web server’s address, asking it to send the web page back to you.
  2. The web server responds by sending a stream of TCP packets, which your web browser stitches together to form the web page.
  3. TCP is all about reliability—packets sent with TCP are tracked so no data is lost or corrupted in transit. This is why file downloads don’t become corrupted even if there are network hiccups. Of course, if the recipient is completely offline, your computer will give up and you’ll see an error message saying it can’t communicate with the remote host.
  4. TCP achieves this in two ways. First, it orders packets by numbering them. Second, it error-checks by having the recipient send a response back to the sender saying that it has received the message. If the sender doesn’t get a correct response, it can resend the packets to ensure the recipient receives them correctly.
17
Q

How does UDP work?

A
  1. When an app uses UDP, packets are just sent to the recipient. The sender doesn’t wait to make sure the recipient received the packet—it just continues sending the next packets. If the recipient misses a few UDP packets here and there, they are just lost—the sender won’t resend them. Losing all this overhead means the devices can communicate more quickly.
  2. The server just sends a constant stream of UDP packets to computers watching. If you lose your connection for a few seconds, the video may freeze or get jumpy for a moment and then skip to the current bit of the broadcast. If you experience minor packet-loss, the video or audio may be distorted for a moment as the video continues to play without the missing data.