{"componentChunkName":"component---src-templates-blog-post-js","path":"/REST/","result":{"data":{"site":{"siteMetadata":{"title":"Recipes Collection","author":"Internet Community"}},"markdownRemark":{"id":"ab5caecb-f951-5830-af52-0ca01299ce21","html":"<h2 id=\"rest\"><a href=\"#rest\" aria-hidden class=\"anchor\"><svg aria-hidden=\"true\" 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>REST</h2>\n<h4 id=\"q---what-is-an-options-request-and-why-is-it-made-by-the-browser\"><a href=\"#q---what-is-an-options-request-and-why-is-it-made-by-the-browser\" aria-hidden class=\"anchor\"><svg aria-hidden=\"true\" 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>Q - What is an OPTIONS Request and why is it made by the browser?</h4>\n<p>Reference - <a href=\"https://stackoverflow.com/questions/29954037/why-is-an-options-request-sent-and-can-i-disable-it\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">https://stackoverflow.com/questions/29954037/why-is-an-options-request-sent-and-can-i-disable-it</a></p>\n<p><code class=\"language-text\">OPTIONS</code> requests are what we call <code class=\"language-text\">pre-flight</code> requests in <code class=\"language-text\">Cross-origin resource sharing (CORS)</code>.</p>\n<p>This pre-flight request is made by some browsers as a safety measure to ensure that the request being done is trusted by the server. Meaning the server understands that the method, origin and headers being sent on the request are safe to act upon.</p>\n<p>Your server should not ignore but handle these requests whenever you’re attempting to do cross origin requests.</p>\n<p>A way to handle these to get comfortable is to ensure that for any path with OPTIONS method the server sends a response with this header</p>\n<p>Access-Control-Allow-Origin: *</p>\n<p>This will tell the browser that the server is willing to answer requests from any origin.</p>\n<p>According to the CORS strategy You can’t just force the browser to stop sending OPTIONS request if it thinks it needs to.</p>\n<p>There are two ways you can work around it:</p>\n<ul>\n<li>Make sure your request is a “simple request”</li>\n<li>Set Access-Control-Max-Age for the OPTIONS request</li>\n</ul>\n<p><strong>Simple request</strong></p>\n<p>A simple cross-site request is one that meets all the following conditions:</p>\n<p>The only allowed methods are:</p>\n<ul>\n<li>GET</li>\n<li>HEAD</li>\n<li>POST</li>\n</ul>\n<p>Apart from the headers set automatically by the user agent (e.g. Connection, User-Agent, etc.), the only headers which are allowed to be manually set are:</p>\n<ul>\n<li>Accept</li>\n<li>Accept-Language</li>\n<li>Content-Language</li>\n<li>Content-Type</li>\n</ul>\n<p>The only allowed values for the Content-Type header are:</p>\n<ul>\n<li>application/x-www-form-urlencoded</li>\n<li>multipart/form-data</li>\n<li>text/plain</li>\n</ul>\n<p>A simple request will not cause a pre-flight OPTIONS request.</p>\n<p><strong>Set a cache for the OPTIONS check</strong></p>\n<p>You can set a Access-Control-Max-Age for the OPTIONS request, so that it will not check the permission again until it is expired.</p>\n<p><code class=\"language-text\">Access-Control-Max-Age</code> gives the value in seconds for how long the response to the preflight request can be cached for without sending another preflight request.</p>","timeToRead":2,"frontmatter":{"title":"REST","date":"November 01, 2019","spoiler":"Following are some notes collected through internet"},"fields":{"slug":"/REST/","langKey":"en"}}},"pageContext":{"slug":"/REST/","previous":{"fields":{"slug":"/javascript/","langKey":"en","directoryName":"javascript","maybeAbsoluteLinks":[]},"frontmatter":{"title":"JavaScript"}},"next":{"fields":{"slug":"/general-knowledge/buddhist-places/sri-pada/","langKey":"en","directoryName":"sri-pada","maybeAbsoluteLinks":[]},"frontmatter":{"title":"සිරිපාදය"}},"translations":[],"translatedLinks":[]}}}