Web Servers (Javalin) & HTTP & REST Flashcards
What are the 3 handler types?
The three handler types in Javalin web framework are:
GET handler: This handler is used to handle HTTP GET requests. It returns a response to the client with the requested resource.
POST handler: This handler is used to handle HTTP POST requests. It is used to create a new resource on the server.
PUT handler: This handler is used to handle HTTP PUT requests. It is used to update an existing resource on the server.
What is a “REST”ful API?
A RESTful API is an architectural style for building web services that follows the principles of the REST (Representational State Transfer) protocol. It is a stateless API that uses HTTP methods to perform operations on resources identified by URIs (Uniform Resource Identifiers). A RESTful API is characterized by the use of HTTP methods such as GET, POST, PUT, DELETE, and others to manipulate resources, and the response from the server is typically in the form of JSON or XML. RESTful APIs are scalable, easily maintainable, and can be used across multiple platforms and programming languages.
What is the difference between the different HTTP methods/verbs?
In HTTP, there are several methods or verbs that can be used to specify the desired action to be performed on a resource. The main HTTP methods are:
GET: Used to retrieve a resource from the server. It is an idempotent and safe operation, meaning that multiple GET requests to the same resource will always return the same response, and it does not modify the resource in any way.
POST: Used to submit data to the server to create a new resource. It is a non-idempotent and unsafe operation, meaning that repeated requests to the same resource can lead to the creation of multiple resources.
PUT: Used to update an existing resource on the server. It is an idempotent and safe operation, meaning that multiple PUT requests to the same resource will always produce the same result, and it modifies the resource on the server.
DELETE: Used to delete a resource from the server. It is an idempotent and unsafe operation, meaning that multiple DELETE requests to the same resource will always produce the same result, and it removes the resource from the server.
PATCH: Used to modify an existing resource on the server. It is a partial update, meaning that it only modifies a portion of the resource. It is idempotent and safe, meaning that repeated requests to the same resource produce the same result, and it modifies the resource on the server.
These HTTP methods/verbs help to standardize the interaction between clients and servers, and allow for efficient and effective resource manipulation.
What are the levels of status codes that can be sent in a response?
here are five levels of HTTP status codes that can be sent in a response:
Informational (1xx): These are interim responses indicating that the server has received the request and is processing it.
Success (2xx): These are responses indicating that the request was successfully received, understood, and accepted by the server.
Redirection (3xx): These are responses indicating that further action needs to be taken by the client to complete the request.
Client errors (4xx): These are responses indicating that the client made a bad request, such as a request for a resource that does not exist or an attempt to access a resource without proper authentication.
Server errors (5xx): These are responses indicating that the server failed to fulfill a valid request, such as due to a server configuration error or an unexpected condition.
What is included in an HTTP Request?
An HTTP request typically includes the following components:
Request line: Contains the HTTP method, URL, and protocol version.
Headers: Contains additional information about the request, such as the user agent, content type, and accept encoding.
Body: Contains optional data to be sent to the server, such as form data or a request payload. This component is not included in all requests, and its presence depends on the HTTP method used and the type of data being sent.
What is included in an HTTP Response?
An HTTP Response is sent from the server to the client in response to an HTTP Request. It consists of the following elements:
Status Line: The first line of the response which contains the HTTP version, status code, and reason phrase.
Response Headers: Additional information about the response, such as content type, length, encoding, caching instructions, etc.
Blank Line: A blank line that separates the headers from the response body.
Response Body: The actual data/content of the response, which can be in various formats such as HTML, JSON, XML, text, etc.
The status line and headers are mandatory in an HTTP response, while the response body is optional depending on the type of request and response.
What is a path parameter and what would it look like?
it to the server as a parameter. In a RESTful API, path parameters are used to identify specific resources and operate on them.
For example, let’s say we have an endpoint for retrieving a user’s information:
GET /users/{id}
The curly braces {} indicate that id is a path parameter. When a client makes a request to this endpoint with a specific id value, the server will receive the id value as a parameter and use it to retrieve the corresponding user’s information.
For instance, if a client sends a request to /users/123, the server will retrieve the information of the user with an ID of 123