HTTP Flashcards
HTTP stands for? Defined as?
Hypertext Transfer Protocol; HTTP is defined as a request/response protocol.
Hypertext
“content with references to other content” This term is used specifically to refer to content in computing, and may include text, images, video, or any other digital content.
Transfer Protocol
It defines the expectations for both ends of the transfer, and it defines some ways the transfer might fail.
HTTP defines the process of …
exchanging hypertext between systems. Specifically, HTTP works between clients and servers. A client (sometimes called the user agent) is the data consumer. This is usually your web browser. A server (sometimes referred to as the origin) is the data provider, often where an application is running. In a typical HTTP exchange, the client sends a request to the server for a particular resource: a webpage, image, or application data. The server provides a response containing either the resource that the client requested or an explanation of why it can’t provide the resource.
HTTP needs these 3 things
reliable connections, stateless transfer, intermediaries - proxies, which may modify your request so it appears to come from a different source, gateways, which pretend to be the resource server you requested, and tunnels, which simply pass your request along.
HTTP Requests - request line
it sets the stage for everything to come. It’s made up of three parts, separated by spaces:
the method, indicated by an HTTP verb,
the URI (Uniform Resource Indicator) that identifies what we’ve requested,
and the HTTP version we expect to use (usually HTTP/1.1 or HTTP/2)
HTTP Requests - header & body
common headers:
host - The root path for our URI. This is typically the domain we’d like to request our resource from
user-agent - This header displays information about which browser the request originated from
referer - This defines the URL you’re coming from.
accept - headers indicate what the client can receive.
content - Content headers define details about the body of the request. The most common content header is Content-Type, which lets the server know what format we’re sending our body data as. This might be application/json from a JavaScript app or application/x-www-form-urlencoded for info submitted from a web form. Content headers will only show up on requests that support content in the body, so GET requests should never have this
body:
The most common way form data is formatted is URL encoding or JSON or XML
HTTP response - status-line
We open with the HTTP version the server is responding with. 1.1 is still the most commonly used, though you may occasionally see 2 or even 1.0. We follow this with a Status-Code and Reason-Phrase. These give us a quick way of understanding if our request was successful or not.
HTTP status responses
Status codes 100 - 199: Informational
Status codes 200 - 299: Successful
200 OK: Request received and fulfilled. These usually come with a body that contains the resource you requested.
201 Created: Your request was received and a new record was created as a result. You’ll often see this response to POST requests.
Status codes 300 - 399: Redirection
301 Moved Permanently, 302 Found
Status codes 400 - 499: Client Error
400 Bad Request: Whoops! The server received your request, but couldn’t understand it. You might see a 400 Bad Request in response to a typo or accidentally truncated request. We often refer to these as malformed requests.
401 Unauthorized: The resource you requested may exist, but you’re not allowed to see it without authentication. These type of responses might mean one of two things: either you didn’t log in yet, or you tried to log in but your credentials aren’t being accepted.
403 Forbidden: The resource you requested may exist, but you’re not allowed to see it at all. This response code means this resource isn’t accessible to you, even if you’re logged in. You just don’t have the correct permission to see it.
404 Not Found: The resource you requested doesn’t exist. You may see this response if you have a typo in your request (for example: going to appaccccademy.io), or if you’re looking for something that has been removed.
Status codes 500 - 599: Server Error
500 Internal Server Error, 504 Gateway Timeout