{"componentChunkName":"component---src-pages-author-author-yaml-id-js","path":"/author/mayank-agarwal/","result":{"data":{"allMarkdownRemark":{"edges":[{"node":{"id":"5f19c8b0-c371-5192-b44e-c9bcec168840","html":"<p>HTTP (hypertext transfer protocol) is a communication protocol that transfers data between client and server. HTTP requests are very essential to access resources from the same or remote server. In Golang, the <code>net/http</code> package comes with the default settings that we need to adjust according to our high-performance requirement.</p>\n<p>For setting up HTTP clients for making requests, most programming languages have different frameworks in place. We will take a hands-on approach in the coming sections to explore how HTTP requests can be made in Golang or Go, as I will refer to the language for the rest of the post.</p>\n<p>While working on the <a href=\"https://www.loginradius.com/blog/engineering/golang-maps/\">Golang projects</a>, I realized that improper configuration of HTTP might crash your server anytime.</p>\n<p>In the time when I was working with HTTP Client, I Observed some problems and their solutions, listed below:</p>\n<h2 id=\"problem1-default-http-client\" style=\"position:relative;\"><a href=\"#problem1-default-http-client\" aria-label=\"problem1 default http client permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Problem:1 Default Http Client</h2>\n<p>The HTTP client does not contain the request timeout setting by default.\nIf you are using http.Get(URL) or &#x26;Client{} that uses the http.DefaultClient. DefaultClient has not timeout setting; it comes with <code>no timeout</code></p>\n<p>Suppose the Rest API where you are making the request is broken, not sending the response back that keeps the connection open. More requests came, and open connection count will increase, Increasing server resources utilization, resulting in crashing your server when resource limits are reached.</p>\n<h3 id=\"solution-dont-use-the-default-http-client-always-specify-the-timeout-in-httpclient-according-to-your-use-case\" style=\"position:relative;\"><a href=\"#solution-dont-use-the-default-http-client-always-specify-the-timeout-in-httpclient-according-to-your-use-case\" aria-label=\"solution dont use the default http client always specify the timeout in httpclient according to your use case permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Solution: Don't use the default HTTP client, always specify the timeout in http.Client according to your use case</h3>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"\" data-index=\"0\"><code class=\"grvsc-code\"><span class=\"grvsc-line\">var httpClient = &http.Client{</span>\n<span class=\"grvsc-line\">  Timeout: time.Second * 10,</span>\n<span class=\"grvsc-line\">}</span></code></pre>\n<p>For the Rest API, it is recommended that timeout should not more than 10 seconds.\nIf the Requested resource is not responded to in 10 seconds, the HTTP connection will be canceled with net/http: request canceled (Client.Timeout exceeded ...) error.</p>\n<h2 id=\"problem2-default-http-transport\" style=\"position:relative;\"><a href=\"#problem2-default-http-transport\" aria-label=\"problem2 default http transport permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Problem:2 Default Http Transport</h2>\n<p>By default, the Golang Http client performs the connection pooling. When the request completes, that connection remains open until the idle connection timeout (default is 90 seconds). If another request came, that uses the same established connection instead of creating a new connection, after the idle connection time, the connection will return to the pool.</p>\n<p>Using the connection pooling will keep less connection open and more requests will be served with minimal server resources.</p>\n<p>When we not defined transport in the http.Client, it uses the default transport <a href=\"https://golang.org/src/net/http/transport.go\">Go HTTP Transport</a></p>\n<p>Default configuration of the HTTP Transport, </p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"\" data-index=\"1\"><code class=\"grvsc-code\"><span class=\"grvsc-line\">var DefaultTransport RoundTripper = &Transport{</span>\n<span class=\"grvsc-line\">\t...</span>\n<span class=\"grvsc-line\">\tMaxIdleConns:          100,</span>\n<span class=\"grvsc-line\">\tIdleConnTimeout:       90 * time.Second,</span>\n<span class=\"grvsc-line\">\t...</span>\n<span class=\"grvsc-line\">}</span>\n<span class=\"grvsc-line\"></span>\n<span class=\"grvsc-line\">const DefaultMaxIdleConnsPerHost = 2</span></code></pre>\n<p>MaxIdleConns is the connection pool size, and this is the maximum connection that can be open; its default value is 100 connections.</p>\n<p>There is problem with the default setting <code>DefaultMaxIdleConnsPerHost</code> with value of 2 connection,\nDefaultMaxIdleConnsPerHost is the number of connection can be allowed to open per host basic.\nMeans for any particular host out of 100 connection from the connection pool only two connection will be allocated to that host.</p>\n<p>With the more request came, it will process only two requests; other requests will wait for the connection to communicate with the host server and go in the <code>TIME_WAIT</code> state. As more request came, increase the connection to the <code>TIME_WAIT</code> state and increase the server resource utilization; at the limit, the server will crash.</p>\n<h3 id=\"solution-dont-use-default-transport-and-increase-maxidleconnsperhost\" style=\"position:relative;\"><a href=\"#solution-dont-use-default-transport-and-increase-maxidleconnsperhost\" aria-label=\"solution dont use default transport and increase maxidleconnsperhost permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Solution: Don't use Default Transport and increase MaxIdleConnsPerHost</h3>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"\" data-index=\"2\"><code class=\"grvsc-code\"><span class=\"grvsc-line\">t := http.DefaultTransport.(*http.Transport).Clone()</span>\n<span class=\"grvsc-line\">t.MaxIdleConns = 100</span>\n<span class=\"grvsc-line\">t.MaxConnsPerHost = 100</span>\n<span class=\"grvsc-line\">t.MaxIdleConnsPerHost = 100</span>\n<span class=\"grvsc-line\">\t</span>\n<span class=\"grvsc-line\">httpClient = &http.Client{</span>\n<span class=\"grvsc-line\">  Timeout:   10 * time.Second,</span>\n<span class=\"grvsc-line\">  Transport: t,</span>\n<span class=\"grvsc-line\">}</span></code></pre>\n<p>By increasing connection per host and the total number of idle connection, this will increase the performance and serve more request with minimal server resources.</p>\n<p>Connection pool size and connection per host count can be increased as per server resources and requirements.</p>\n<h2 id=\"conclusion\" style=\"position:relative;\"><a href=\"#conclusion\" aria-label=\"conclusion permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Conclusion</h2>\n<p>In this article, we discussed the problems around the 'net/http' client default configurations. By changing some of the default settings of HTTP Client, we can achieve a High-performance HTTP client for production use. If you want to learn more about http, here is an interesting post on <a href=\"https://www.loginradius.com/blog/engineering/http-security-headers/\">HTTP security headers</a> If you like what you read, share your thoughts in the comment section.</p>\n<style class=\"grvsc-styles\">\n  .grvsc-container {\n    overflow: auto;\n    -webkit-overflow-scrolling: touch;\n    padding-top: 1rem;\n    padding-top: var(--grvsc-padding-top, var(--grvsc-padding-v, 1rem));\n    padding-bottom: 1rem;\n    padding-bottom: var(--grvsc-padding-bottom, var(--grvsc-padding-v, 1rem));\n    border-radius: 8px;\n    border-radius: var(--grvsc-border-radius, 8px);\n    font-feature-settings: normal;\n  }\n  \n  .grvsc-code {\n    display: inline-block;\n    min-width: 100%;\n  }\n  \n  .grvsc-line {\n    display: inline-block;\n    box-sizing: border-box;\n    width: 100%;\n    padding-left: 1.5rem;\n    padding-left: var(--grvsc-padding-left, var(--grvsc-padding-h, 1.5rem));\n    padding-right: 1.5rem;\n    padding-right: var(--grvsc-padding-right, var(--grvsc-padding-h, 1.5rem));\n  }\n  \n  .grvsc-line-highlighted {\n    background-color: var(--grvsc-line-highlighted-background-color, transparent);\n    box-shadow: inset var(--grvsc-line-highlighted-border-width, 4px) 0 0 0 var(--grvsc-line-highlighted-border-color, transparent);\n  }\n  \n  .dark-default-dark {\n    background-color: #1E1E1E;\n    color: #D4D4D4;\n  }\n</style>","frontmatter":{"title":"How to Use the HTTP Client in GO To Enhance Performance","author":{"id":"Mayank Agarwal","github":"mayankagrwal","avatar":null},"date":"January 12, 2021","updated_date":null,"tags":["Golang","HTTP","Performance"],"coverImage":{"childImageSharp":{"fluid":{"aspectRatio":1.7699115044247788,"src":"/static/68276d4b4277ad09e329598038e91917/14b42/index.jpg","srcSet":"/static/68276d4b4277ad09e329598038e91917/f836f/index.jpg 200w,\n/static/68276d4b4277ad09e329598038e91917/2244e/index.jpg 400w,\n/static/68276d4b4277ad09e329598038e91917/14b42/index.jpg 800w,\n/static/68276d4b4277ad09e329598038e91917/47498/index.jpg 1200w,\n/static/68276d4b4277ad09e329598038e91917/ec6c5/index.jpg 1280w","sizes":"(max-width: 800px) 100vw, 800px"}}}},"fields":{"authorId":"Mayank Agarwal","slug":"/engineering/tune-the-go-http-client-for-high-performance/"}}},{"node":{"id":"6ce369df-8811-5c71-9d65-a5ad1f848f8b","html":"<p><em>A JSON Web Token (JWT) is a JSON object that is defined in</em> <a href=\"https://tools.ietf.org/html/rfc7519\"><em>RFC 7519</em></a> <em>as a safe way</em> of <em>transmitting information between two parties. Information in the JWT is digitally-signed, so that it can be verified and trusted.</em></p>\n<p><strong>JWT Properties</strong></p>\n<ul>\n<li>Less verbose -  JWT is compact in size and can be passed in the URL, POST parameter, or HTTP header.</li>\n<li>Self-contained - JWT carries all of information needed for exchanging information and authentication.</li>\n<li>Versatile - JWT works in .NET, Python, Node.js, Java, PHP, Ruby, Go, JavaScript, and Haskell.</li>\n</ul>\n<p><strong>JWT Use Cases</strong></p>\n<ul>\n<li>Information Exchange - JWT can be used between two parties to exchange information. JWT is digitally-signed and can be used in a secure public/private key pair. Information is verified using the public key on the other end.</li>\n<li>Authentication - JWT can contain user information in the payload and can be used in the session to authenticate the user. Once authenticated, users can access protected resources in an application using the JWT included in the request. So, every request will be authenticated by verifying the JWT.</li>\n</ul>\n<p>JWT contains three parts: Header, Payload, and Signature which are separated by a dot.</p>\n<p><code>Header.Payload.Signature</code></p>\n<p><strong>Header</strong></p>\n<p>The JWT Header consists of 2 parts:</p>\n<ul>\n<li>The token type (typ): JWT </li>\n<li>Algorithm used to sign the token (alg)</li>\n</ul>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"json\" data-index=\"0\"><code class=\"grvsc-code\"><span class=\"grvsc-line\"><span class=\"mtk1\">{  </span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\"> </span><span class=\"mtk12\">&quot;typ&quot;</span><span class=\"mtk1\"> : </span><span class=\"mtk8\">&quot;JWT&quot;</span><span class=\"mtk1\">,  </span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\"> </span><span class=\"mtk12\">&quot;alg&quot;</span><span class=\"mtk1\"> : </span><span class=\"mtk8\">&quot;HS256&quot;</span><span class=\"mtk1\">  </span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">}</span></span></code></pre>\n<p>Header Algorithm Types:</p>\n<ul>\n<li>Symmetric Algorithms - This algorithm type uses a single secret key to both sign and verify the JWT token. For example: HMAC algorithms.</li>\n<li>Asymmetric Algorithms - This algorithm type uses a private key to sign the token and a public key to verify the signature. For example: RSA and ECDSA algorithms.</li>\n</ul>\n<p><strong>alg Value</strong></p>\n<p><strong>Digital Signature or MAC Algorithm</strong></p>\n<table>\n<thead>\n<tr>\n<th>Algo</th>\n<th align=\"center\">Description</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td>HS256</td>\n<td align=\"center\">HMAC using SHA-256 hash algorithm</td>\n</tr>\n<tr>\n<td>HS384</td>\n<td align=\"center\">HMAC using SHA-384 hash algorithm</td>\n</tr>\n<tr>\n<td>HS512</td>\n<td align=\"center\">HMAC using SHA-512 hash algorithm</td>\n</tr>\n<tr>\n<td>RS256</td>\n<td align=\"center\">RSASSA using SHA-256 hash algorithm</td>\n</tr>\n<tr>\n<td>RS384</td>\n<td align=\"center\">RSASSA using SHA-384 hash algorithm</td>\n</tr>\n<tr>\n<td>RS512</td>\n<td align=\"center\">RSASSA using SHA-512 hash algorithm</td>\n</tr>\n<tr>\n<td>ES256</td>\n<td align=\"center\">ECDSA using P-256 curve and SHA-256 hash algorithm</td>\n</tr>\n<tr>\n<td>ES384</td>\n<td align=\"center\">ECDSA using P-384 curve and SHA-384 hash algorithm</td>\n</tr>\n<tr>\n<td>ES512</td>\n<td align=\"center\">ECDSA using P-521 curve and SHA-512 hash algorithm</td>\n</tr>\n</tbody>\n</table>\n<p>The Base64Url-encoded Header<strong>,</strong> which is first part of our JWT, looks like the following:</p>\n<p><code>eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9</code></p>\n<p><strong>Payload</strong></p>\n<p>The Payload, also known as the JWT claim, contains all of the information we want to transmit.</p>\n<p>Different types of claims can be used to build the Payload:</p>\n<ul>\n<li><strong>Registered Claim</strong> -  These claims are optional but recommended as they contain some metadata about the token:</li>\n</ul>\n<table>\n<thead>\n<tr>\n<th>Code</th>\n<th>Name</th>\n<th align=\"center\">Description</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td>iss</td>\n<td>issuer</td>\n<td align=\"center\">Identifies the principal that issued the JWT.</td>\n</tr>\n<tr>\n<td>sub</td>\n<td>subject</td>\n<td align=\"center\">Identifies the principal that is the subject of the JWT.</td>\n</tr>\n<tr>\n<td>aud</td>\n<td>audience</td>\n<td align=\"center\">Identifies the recipients that the JWT is intended for.</td>\n</tr>\n<tr>\n<td>exp</td>\n<td>Expiration time</td>\n<td align=\"center\">Identifies the expiration time on or after which the JWT MUST NOT be accepted for processing.</td>\n</tr>\n<tr>\n<td>nbf</td>\n<td>Not before</td>\n<td align=\"center\">Identifies the time before which the JWT MUST NOT be accepted for processing.</td>\n</tr>\n<tr>\n<td>iat</td>\n<td>Issue at</td>\n<td align=\"center\">Identifies the time at which the JWT was issued.</td>\n</tr>\n<tr>\n<td>jti</td>\n<td>JWT id</td>\n<td align=\"center\">Unique identifier for the JWT, can be used to prevent the JWT from being replayed.</td>\n</tr>\n</tbody>\n</table>\n<ul>\n<li><strong>Public Claim</strong> - These claims are defined by you, such as user name, and other important information.</li>\n<li><strong>Private Claim</strong> - A producer and consumer may agree to use claim names that are private. These are subject to collision, so use them with caution.</li>\n</ul>\n<p>Example Payload:</p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"json\" data-index=\"1\"><code class=\"grvsc-code\"><span class=\"grvsc-line\"><span class=\"mtk1\">{  </span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\"> </span><span class=\"mtk12\">&quot;sub&quot;</span><span class=\"mtk1\">: </span><span class=\"mtk8\">&quot;1234567890&quot;</span><span class=\"mtk1\">,  </span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\"> </span><span class=\"mtk12\">&quot;name&quot;</span><span class=\"mtk1\">: </span><span class=\"mtk8\">&quot;Frank Emic&quot;</span><span class=\"mtk1\">,  </span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\"> </span><span class=\"mtk12\">&quot;jti&quot;</span><span class=\"mtk1\">: </span><span class=\"mtk8\">&quot;4b5fcea6-2a5e-4a9d-97f2-3d8631ea2c5a&quot;</span><span class=\"mtk1\">,  </span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\"> </span><span class=\"mtk12\">&quot;iat&quot;</span><span class=\"mtk1\">: </span><span class=\"mtk7\">1521191902</span><span class=\"mtk1\">,  </span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\"> </span><span class=\"mtk12\">&quot;exp&quot;</span><span class=\"mtk1\">: </span><span class=\"mtk7\">1521195630</span><span class=\"mtk1\">  </span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">}</span></span></code></pre>\n<p>This example contains a combination of registered and public claims. “sub”,”jti”,”iat”, and “exp” are registered claims and “name” is a public claim.</p>\n<p>The Base64Url-encoded Payload, which is the second part of our JWT, looks like the following:</p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"json\" data-index=\"2\"><code class=\"grvsc-code\"><span class=\"grvsc-line\"><span class=\"mtk1\">eyJzdWIiOiIxMjM</span><span class=\"mtk7\">0</span><span class=\"mtk1\">NTY</span><span class=\"mtk7\">3</span><span class=\"mtk1\">ODkwIiwibmFtZSI</span><span class=\"mtk7\">6</span><span class=\"mtk1\">IkZyYW</span><span class=\"mtk7\">5</span><span class=\"mtk1\">rIEVtaWMiL  </span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">CJqdGkiOiI</span><span class=\"mtk7\">0</span><span class=\"mtk1\">YjVmY</span><span class=\"mtk7\">2</span><span class=\"mtk1\">VhNi</span><span class=\"mtk7\">0</span><span class=\"mtk1\">yYTVlLTRhOWQtOTdmMi</span><span class=\"mtk7\">0</span><span class=\"mtk1\">zZDg</span><span class=\"mtk7\">2</span><span class=\"mtk1\">MzFlYTJjNWEiLCJpYXQiOjE</span><span class=\"mtk7\">1</span><span class=\"mtk1\">MjExOTE</span><span class=\"mtk7\">5</span><span class=\"mtk1\">MDIsImV</span><span class=\"mtk7\">4</span><span class=\"mtk1\">cCI</span><span class=\"mtk7\">6</span><span class=\"mtk1\">MTUyMTE</span><span class=\"mtk7\">5</span><span class=\"mtk1\">NTYzMH</span><span class=\"mtk7\">0</span></span></code></pre>\n<p><strong>Signature</strong></p>\n<p>The final part of our JWT is the Signature. To create the Signature, we need 3 components:</p>\n<ul>\n<li>Header</li>\n<li>Payload</li>\n<li>Algorithm used to sign the Header and Payload</li>\n</ul>\n<p>var encodedString = base64UrlEncode(header) + \".\" + base64UrlEncode(payload);<br>\nHMACSHA256(encodedString, 'secret');</p>\n<p>The secret is the Signature held by the server in order to verify tokens and sign new ones.</p>\n<p>The above Base64Url-encoded Header and Payload are combined with a dot, and then digitally-signed using the secret. This generates the Signature as the third part of the our JWT:</p>\n<p>wGDoDSxfKj3Ns379NVxocwM9TOiwxhxWl</p>\n<p><strong>Putting It All Together</strong></p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"json\" data-index=\"3\"><code class=\"grvsc-code\"><span class=\"grvsc-line\"><span class=\"mtk1\">eyJhbGciOiJIUzI</span><span class=\"mtk7\">1</span><span class=\"mtk1\">NiIsInR</span><span class=\"mtk7\">5</span><span class=\"mtk1\">cCI</span><span class=\"mtk7\">6</span><span class=\"mtk1\">IkpXVCJ</span><span class=\"mtk7\">9</span><span class=\"mtk1\">.eyJzdWIiOiIxMjM</span><span class=\"mtk7\">0</span><span class=\"mtk1\">NTY</span><span class=\"mtk7\">3</span><span class=\"mtk1\">ODkwIiwibmFtZSI</span><span class=\"mtk7\">6</span><span class=\"mtk1\">IkZyYW</span><span class=\"mtk7\">5</span><span class=\"mtk1\">rIEVtaWMiL  </span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">CJqdGkiOiI</span><span class=\"mtk7\">0</span><span class=\"mtk1\">YjVmY</span><span class=\"mtk7\">2</span><span class=\"mtk1\">VhNi</span><span class=\"mtk7\">0</span><span class=\"mtk1\">yYTVlLTRhOWQtOTdmMi</span><span class=\"mtk7\">0</span><span class=\"mtk1\">zZDg</span><span class=\"mtk7\">2</span><span class=\"mtk1\">MzFlYTJjNWEiLCJpYXQiOjE</span><span class=\"mtk7\">1</span><span class=\"mtk1\">MjExOTE</span><span class=\"mtk7\">5</span><span class=\"mtk1\">MDIsImV</span><span class=\"mtk7\">4</span><span class=\"mtk1\">cCI</span><span class=\"mtk7\">6</span><span class=\"mtk1\">MTUyMTE</span><span class=\"mtk7\">5</span><span class=\"mtk1\">NTYzMH</span><span class=\"mtk7\">0</span><span class=\"mtk1\">.wGDoDSxfKj</span><span class=\"mtk7\">3</span><span class=\"mtk1\">Ns</span><span class=\"mtk7\">379</span><span class=\"mtk1\">NVxocwM</span><span class=\"mtk7\">9</span><span class=\"mtk1\">TOiwxhxWl</span></span></code></pre>\n<p>This is our final JWT, containing the Header, Payload, and Signature joined together with dots. It can be passed as a URL parameter, a POST parameter, or in the  HTTP header to authenticate or exchange information.</p>\n<p>You can play around with JWT using our <a href=\"https://jwt.io/\">JWT SSO Tool.</a></p>\n<p>Note: JWT does not hide information; it just encodes information using the digitally-signed signature and verifies that the information has not been altered over the network. So, do not add any sensitive information in the JWT claim.</p>\n<p><strong>Conclusion</strong></p>\n<p>JWT comprises three encoded parts: Header, Payload, and Signature. It can be passed as a URL or POST parameter, or in an HTTP header. Due to JWT's lightweight, self-containing, and versatile strucutre, it remains a popular tool for information exchange and authentication.</p>\n<style class=\"grvsc-styles\">\n  .grvsc-container {\n    overflow: auto;\n    -webkit-overflow-scrolling: touch;\n    padding-top: 1rem;\n    padding-top: var(--grvsc-padding-top, var(--grvsc-padding-v, 1rem));\n    padding-bottom: 1rem;\n    padding-bottom: var(--grvsc-padding-bottom, var(--grvsc-padding-v, 1rem));\n    border-radius: 8px;\n    border-radius: var(--grvsc-border-radius, 8px);\n    font-feature-settings: normal;\n  }\n  \n  .grvsc-code {\n    display: inline-block;\n    min-width: 100%;\n  }\n  \n  .grvsc-line {\n    display: inline-block;\n    box-sizing: border-box;\n    width: 100%;\n    padding-left: 1.5rem;\n    padding-left: var(--grvsc-padding-left, var(--grvsc-padding-h, 1.5rem));\n    padding-right: 1.5rem;\n    padding-right: var(--grvsc-padding-right, var(--grvsc-padding-h, 1.5rem));\n  }\n  \n  .grvsc-line-highlighted {\n    background-color: var(--grvsc-line-highlighted-background-color, transparent);\n    box-shadow: inset var(--grvsc-line-highlighted-border-width, 4px) 0 0 0 var(--grvsc-line-highlighted-border-color, transparent);\n  }\n  \n  .dark-default-dark {\n    background-color: #1E1E1E;\n    color: #D4D4D4;\n  }\n  .dark-default-dark .mtk1 { color: #D4D4D4; }\n  .dark-default-dark .mtk12 { color: #9CDCFE; }\n  .dark-default-dark .mtk8 { color: #CE9178; }\n  .dark-default-dark .mtk7 { color: #B5CEA8; }\n</style>","frontmatter":{"title":"What is JSON Web Token","author":{"id":"Mayank Agarwal","github":"mayankagrwal","avatar":null},"date":"July 11, 2018","updated_date":null,"tags":["JWT","JSON Web Token"],"coverImage":{"childImageSharp":{"fluid":{"aspectRatio":1.7699115044247788,"src":"/static/280ee8f1345faeaa2d33899ee2475b0b/ee604/jwt.png","srcSet":"/static/280ee8f1345faeaa2d33899ee2475b0b/69585/jwt.png 200w,\n/static/280ee8f1345faeaa2d33899ee2475b0b/497c6/jwt.png 400w,\n/static/280ee8f1345faeaa2d33899ee2475b0b/ee604/jwt.png 800w,\n/static/280ee8f1345faeaa2d33899ee2475b0b/f3583/jwt.png 1200w,\n/static/280ee8f1345faeaa2d33899ee2475b0b/e4d72/jwt.png 1280w","sizes":"(max-width: 800px) 100vw, 800px"}}}},"fields":{"authorId":"Mayank Agarwal","slug":"/engineering/jwt/"}}}]},"authorYaml":{"id":"Mayank Agarwal","bio":"Mayank is a Software developer at LoginRadius. He graduated with a Bachelor of Technology Degree in Computer Science. He loves to play cricket, watching TV series and listening music.","github":"mayankagrwal","stackoverflow":null,"linkedin":null,"medium":null,"twitter":null,"avatar":null}},"pageContext":{"id":"Mayank Agarwal","__params":{"id":"mayank-agarwal"}}},"staticQueryHashes":["1171199041","1384082988","2100481360","23180105","528864852"]}