HTTTP/Middleware/MVC Flashcards
Kestrel
Kestrel is a cross-platform web server for ASP.NET Core, a web framework for building modern, cloud-based, and internet-connected applications. It is the default web server included with ASP.NET Core projects and is designed to be lightweight, high-performance, and scalable.
Reverse proxy servers- examples
IIS
Nginx
Apache
Reverse proxy to serwer, który przyjmuje żądania HTTP od klientów (np. przeglądarek) i przekazuje je do jednego lub więcej serwerów aplikacji w celu przetworzenia. Odpowiedzi z serwera aplikacji są następnie wysyłane z powrotem do klienta przez serwer proxy. W przeciwieństwie do forward proxy, który działa w imieniu klienta, reverse proxy działa w imieniu serwera.
Benefits of Reverse Proxy Servers
Load Balancing
Caching
URL Rewriting
Decompressing the requests
Authentication
Decryption of SSL Certificates
IIS express benefits
HTTP access logs
Port sharing
Windows authentication
Management console
Process activation
Configuration API
Request filters
HTTP redirect rules
HTTP
is an application-protocol that defines set of rules to send request from browser to server and send response from server to browser.
HTTP Response Status Codes
1xx | Informational
101 Switching Protocols
2xx | Success
200 OK
3xx | Redirection
302 Found
304 Not Modified
4xx | Client error
400 Bad Request
401 Unauthorized
404 Not Found
5xx | Server error
500 Internal Server Error
Response Start Line
Includes HTTP version, status code and status description.
HTTP Version: 1/1 | 2 | 3
Status Code: 101 | 200 | 302 | 400 | 401 | 404 | 500
Status Description: Switching Protocols | OK | Found | Bad Request | Unauthorized | Not Found | Internal Server Error
HTTP Response Headers
Date
Date and time of the response. Ex: Tue, 15 Nov 1994 08:12:31 GMT
Server
Name of the server.
Ex: Server=Kestrel
Content-Type
MIME type of response body.
Ex: text/plain, text/html, application/json, application/xml etc.
Content-Length
Length (bytes) of response body.
Ex: 100
Cache-Control
Indicates number of seconds that the response can be cached at the browser.
Ex: max-age=60
Set-Cookie
Contains cookies to send to browser.
Ex: x=10
HTTP Request Methods
GET
Requests to retrieve information (page, entity object or a static file).
Post
Sends an entity object to server; generally, it will be inserted into the database.
Put
Sends an entity object to server; generally updates all properties (full-update) it in the database.
Patch
Sends an entity object to server; generally updates few properties (partial-update) it in the database.
Delete
Requests to delete an entity in the database.
GET request
Used to retrieve data from server.
Parameters will be in the request url (as query string only).
Can send limited number of characters only to server. Max: 2048 characters
Used mostly as a default method of request for retrieving page, static files etc.
Can be cached by browsers / search engines.
POST request
Used to insert data into server
Parameters will be in the request body (as query string, json, xml or form-data).
Can send unlimited data to server.
Mostly used for form submission / XHR calls
Can’t be cached by browsers / search engines.
Middleware
Middleware is a component that is assembled into the application pipeline to handle requests and responses.
Middlewares are chained one-after-other and execute in the same sequence how they’re added.
Middleware can be a request delegate (anonymous method or lambda expression) [or] a class.
Http Context + Next
Middleware - Run
app.Run( )
The extension method called “Run” is used to execute a terminating / short-circuiting middleware that doesn’t forward the request to the next middleware.
app.Use( )
The extension method called “Use” is used to execute a non-terminating / short-circuiting middleware that may / may not forward the request to the next middleware.
Middleware Class
class MiddlewareClassName : IMiddleware
{
public async Task InvokeAsync(HttpContext context, RequestDelegate next)
{
//before logic
await next(context);
//after logic
}
}
app.UseMiddleware<MiddlewareClassName>();</MiddlewareClassName>
Middleware extension method is used to invoke the middleware with a single method call.