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

 



No comments:

Post a Comment