http headers in webapi

Htttp Header:- Http Header is a field of an HTTP request or response that passes additional info about the request or response. For example, a request message can use headers to indicate it's preferred media formats, while a response can use header to indicate the media format of the returned body.


Request Headers:- Headers containing more information about the resource to be fetched or about the client itself or we can say that Http headers that have additional info about the request.Types of Request headers:- 

  • Accept
  • Accept-Encoding
  • Authorization 
  • Origin
  • Referer
  • User-Agent
  • If-Modified Since
  • If-None-Match
  • Cookie
  • Host


Response Headers:- Headers with additional information about the response, like its location or about the server itself (name, version, …). Types of Response Header:-

  • Pragma
  • Server
  • Set-Cookie
  • www-Authentication:- Basic,Bearer Token,Digest etc
  • x-Frame-options
  • Cache-Control
  • Location
  • Expire



Representation Header:- metadata about the resource in the message body (e.g. encoding, media type, etc.). 
OR
Http headers that additional info for both request and response but no relation with the data transmitted in the body . They are formely known as General headers.
  • Content-Type
  • Content-Encoding
  • Content-Length
  • Connection
  • Transfer-Encoding  

Fetch Metadata Request Header:- Headers with metadata about the resource in the message body (e.g. encoding, media type, etc.).

  • Sec-Fetch-Site
  • Sec-Fetch-Mode
  • Sec-Fetch-User
  • Sec-Fetch-Dest  

Note:-The current HTTP/1.1 specification no longer refers to entities, entity headers or entity-body. Some of the fields are now referred to as Representation headefields.


Difference between Accept header and Content-Type header

The Accept header attribute specifies the format of response data which the client expects.


GET /posts HTTP/1.1 

Accept:application/json 


GET /posts/42 HTTP/1.1 

             Accept: application/xml 


Content-Type header attribute specifies the format of the data in the request body so that receiver can parse it into appropriate format.


             ContentType: application/x-www-form-urlencoded

             ContentType: application/multipart/form-data

 



How to upload large files using MVC




 This is the third post of file upload in mvc ,first was Upload a File In MVC , second was  Upload Multiple File In MVC  and this is Third "Big File Upload In MVC". In ASP.NET default size of uploading a file is 4MB if  we want to upload a file bigger than 4MB size than we need to have some changes in Web.config file. Lets start

Step1:- For creating a file upload application follow this link Upload a File In MVC  or  Upload Multiple File In MVC    

UploadFile.Cshtml

@{
    ViewBag.Title = "UploadFile";
}
<h2>UploadFile</h2>
 
@using (Html.BeginForm("UploadFile""FileUploading"FormMethod.Post, new { enctype = "multipart/form-data" }))
{
    <div>
        <br />
        <input type="file" id="files" name="files" multiple>
        <input type="submit" value="Upload" />
        @ViewBag.Message
    </div>
}

Differences between Row_Number(), Rank(), Dense_Rank() Functions in SQL Server



All three function  known as a window function in Microsoft SQL Server, the difference between rank()dense_rank(), and row_number() comes when you have duplicate records in a columns where you want to apply ranking For example, if you are ranking employees by their salaries then what would be the rank of two employees of the same salaries? It depends on which ranking function you are using like row_number, rank, or dense_rank.


CREATE TABLE [dbo].[employee](
       [id] [int] 
IDENTITY(1,1) NOT NULL,
       [name] [nvarchar]
(50) NULL,
       [age] [int] 
NULL,
       [salary] [decimal]
(18, 0) NULL
)


SELECT *
FROM employee

 


 

ROW_NUMBER():- The row_number() function always generates a unique ranking even with duplicate records. As you can see below in  query result.


SELECT *,
       
ROW_NUMBER() OVER (ORDER BY id) AS Ranking
FROM employee

 





RANK():-  The rank() function will assign the same rank to the same values . But, the next different rank will not start from immediately next number but there will be a double increment like u can see in employee id 1 that is start from ranking 3 skip the ranking 2.


SELECT *,
       RANK() OVER (ORDER BY salary ) AS Ranking
FROM employee

 

 


 

 

Dense_Rank():-  The dense_rank function is similar to the rank() window function i.e. same values will be assigned the same rank, but the next different value will have a rank which is just one more than the previous rank.

 

SELECT *,
       DENSE_RANK() OVER (ORDER BY salary ) AS Ranking
FROM employee




 

WebApi2 Interview Question

 

  1. What is API.
  2. What is WebAPI.
  3. What is Asp.NET  WebAPI.
  4. What is Rest or Restfull architecturure.
  5. Naming Convention In WebAPI.
  6. What is Routing in WebAPI and How to configure WebAPI.
  7. Difference between MVC Controller And WebAPI Controller.
  8. What is Parameter Binding  in WebAPI. What is the default parameter binding process and how we can change it.
  9. Different types of Http request in Web API and their status code. What is the difference between Http Post and Put request.
  10. Action method return type of WebAPI. What is difference between HttpResponseMessage and IHttpActionResult.
  11. What is Data Formats in WebAPI. What is difference between Accept and Content-Type attribute. 
  12. How we can Authenticate a WebAPI. Difference between Basic Authentication and Token Based Authentication.
  13. What is  Media-Type Formatters in WebAPI.
  14. How to consume Web API in ASP.NET MVC and what is the difference between WebClient and HttpClient.
  15. What is Same Origin Policy of web browser. What is Cross-Origin Resource Sharing (CORS) and how to enable it in WebAPI.
  16. What is oData in WebAPI.
  17. What Web API versioning.   
  18. Difference between Asp.NET WebAPI and Asp.NET MVC
  19. Difference between GET and POST request.
  20. What is Content Negotiation.