<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:atom="https://www.w3.org/2005/Atom" xmlns:sy="https://purl.org/rss/1.0/modules/syndication/" xmlns:dc="https://purl.org/dc/elements/1.1/" xmlns:content="https://purl.org/rss/1.0/modules/content/" xmlns:wfw="https://wellformedweb.org/CommentAPI/" xmlns:slash="https://purl.org/rss/1.0/modules/slash/"
  version="2.0">
  <channel>
    <title>Geo-Replication failover using RESTAPI call</title>
    <atom:link
      href="https://docs.microsoft.com/archive/blogs/suhaspv/feed.xml"
      rel="self"
      type="application/rss+xml" />
    <link>https://docs.microsoft.com/archive/blogs/suhaspv/feed.xml</link>
    <description>Geo-Replication failover using RESTAPI call</description>
    <lastBuildDate>Wed, 17 Apr 2019 03:53:03 GMT</lastBuildDate>
    <language>en-US</language>
    <sy:updatePeriod>hourly</sy:updatePeriod>
    <sy:updateFrequency>1</sy:updateFrequency>
    <item>
      <title>Azure PAAS SQL DB GEO REPLICATION FAIL OVER TESTING USING REST API</title>
      <link>https://docs.microsoft.com/archive/blogs/suhaspv/geo-replication-fail-over-testing-using-rest-api</link>
      <pubDate>Tue, 22 Nov 2016 18:09:01 GMT</pubDate>
      <dc:creator><![CDATA[Suhas Pv]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/suhaspv/?p=35</guid>
      <description><![CDATA[What is REST ? 

Representational state transfer (REST) is an architectural style...]]></description>
      <content:encoded><![CDATA[<table id="layoutsTable">
<tbody>
<tr>
<td>
<div class="ms-rte-layoutszone-outer">
<div class="ms-rte-layoutszone-inner">

<strong class="ms-rteThemeForeColor-5-5">What is REST ? </strong>

<strong class="ms-rteFontFace-12 ms-rteThemeForeColor-5-4"><span class="ms-rteFontFace-12 ms-rteThemeForeColor-5-4">Representational state transfer</span></strong><span class="ms-rteFontFace-12 ms-rteThemeForeColor-5-4"> (</span><strong class="ms-rteFontFace-12 ms-rteThemeForeColor-5-4">REST</strong><span class="ms-rteFontFace-12 ms-rteThemeForeColor-5-4">) is an architectural style of </span><a href="https://en.wikipedia.org/wiki/Application_programming_interface"><span class="ms-rteFontFace-12 ms-rteThemeForeColor-5-4">application programming interfaces</span></a><span class="ms-rteFontFace-12 ms-rteThemeForeColor-5-4"> . Its purpose is to induce performance, scalability, simplicity, modifiability, visibility, portability, and reliability. REST is the </span><a href="https://en.wikipedia.org/wiki/Software_architecture_styles_and_patterns"><span class="ms-rteFontFace-12 ms-rteThemeForeColor-5-4">software architectural style</span></a><span class="ms-rteFontFace-12 ms-rteThemeForeColor-5-4"> of the </span><a href="https://en.wikipedia.org/wiki/World_Wide_Web"><span class="ms-rteFontFace-12 ms-rteThemeForeColor-5-4">World Wide Web</span></a><span class="ms-rteFontFace-12 ms-rteThemeForeColor-5-4">.</span>

<span class="ms-rteThemeForeColor-5-5"><strong>What is REST API</strong>? </span>

<span class="ms-rteFontFace-12 ms-rteThemeForeColor-5-4">A REST API defines a set of functions which developers can use to perform requests and receive responses via HTTP protocol such as GET and POST.</span>

<span class="ms-rteFontFace-12 ms-rteThemeForeColor-5-4">REST API's works very similar to website in a browser. A resource is exposed to a program/software via a URL. The program can access that URL and receive data about the resource. This is very similar to you typing in a URL to your browser and getting a web page back.</span>

<span class="ms-rteFontFace-12 ms-rteThemeForeColor-5-4">REST API's use HTTP.  They can be used by any programming language and easy to test. </span>

&nbsp;

<strong>What is REST API</strong>?

<span class="ms-rteFontFace-12 ms-rteThemeForeColor-5-4">Azure provides REST API's for performing requests/responses so that programmers can benefit from using them and can programmatically access the resources in Azure. A few examples that comes to my mind are – Import/Export, Performing Geo-replication failovers and Performing Point-in time restore. </span>

<span class="ms-rteFontFace-12 ms-rteThemeForeColor-5-4"> </span>

<span class="ms-rteThemeForeColor-5-5"><strong>How to Test REST APIs</strong>? </span>

<span class="ms-rteThemeForeColor-5-4 ms-rteFontFace-12">Programmers often want to test whether the REST API calls are working fine before implementing in the code changes. A simple of testing whether the REST API calls are working is by using POSTMAN client which is an add-on to Google chrome browser. It is an intuitive user interface that would make testing APIs effortless.</span>

<span class="ms-rteThemeForeColor-5-5"><span class="ms-rteThemeForeColor-5-4 ms-rteFontFace-12">It can be downloaded from the URL :-</span>
<a href="https://chrome.google.com/webstore/detail/postman/fhbjgbiflinjbdggehcddcbncdddomop">https://chrome.google.com/webstore/detail/postman/fhbjgbiflinjbdggehcddcbncdddomop</a>
<span class="ms-rteFontFace-12 ms-rteThemeForeColor-5-4">or </span>
<a href="https://www.getpostman.com/">https://www.getpostman.com/</a></span>

&nbsp;

<span class="ms-rteThemeForeColor-5-5"><strong>Testing Azure REST API using POSTMAN Client :</strong></span>

<span class="ms-rteFontFace-12 ms-rteThemeForeColor-5-4">We can test REST API call for Azure using POSTMAN client. The scenario chosen in this context is - Initiating an unplanned failover from the primary database to the secondary database for an Azure SQL database configured for Geo-replication. We are going to use OAuth 2.0 as authentication mechanism for this demo. In short, we are going to use OAuth 2.0 to generate access token by passing Auth URL, Token URL, client id and client secret.</span>

<span class="ms-rteFontFace-12 ms-rteThemeForeColor-5-4">If you are interested in learning more about OAuth 2.0, the following article can help you.</span>

<a href="https://azure.microsoft.com/en-us/documentation/articles/active-directory-protocols-oauth-code">https://azure.microsoft.com/en-us/documentation/articles/active-directory-protocols-oauth-code</a>

<strong>Below are the detailed steps that needs to be followed to achieve this :</strong>

<span class="ms-rteFontFace-12 ms-rteThemeForeColor-5-4">1. Create a new active directory if you don't have one. If you already have one, you can use the existing active directory.</span>

2. Add an application to the active directory.

<img src="https://msdnshared.blob.core.windows.net/media/2016/11/suhas1-1024x707.png" alt="suhas1" width="708" height="489" class="wp-image-246 aligncenter" />

<span class="ms-rteThemeForeColor-5-4 ms-rteFontFace-12"> </span>

<span class="ms-rteThemeForeColor-5-4 ms-rteFontFace-12">3. Feed in the application name of your choice and ensure that the WEB APPLICATION AND/OR WEB API  is  </span><span class="ms-rteThemeForeColor-5-4 ms-rteFontFace-12">selected.</span>

<img src="https://msdnshared.blob.core.windows.net/media/2016/11/Capture26.png" alt="capture2" width="590" height="351" class="wp-image-85 aligncenter" />

&nbsp;

<span class="ms-rteThemeForeColor-5-4 ms-rteFontFace-12">4. Enter the sign in URL and APP ID URL of your choice.</span>

<img src="https://msdnshared.blob.core.windows.net/media/2016/11/Capture44.png" alt="capture4" width="606" height="291" class="wp-image-95 aligncenter" />

&nbsp;

<span class="ms-rteFontFace-12 ms-rteThemeForeColor-5-4">5. Wait for the application to get created until you see the success message.</span>

<span class="ms-rteFontFace-12 ms-rteThemeForeColor-5-4">6. Click on the configure tab.</span>

<img src="https://msdnshared.blob.core.windows.net/media/2016/11/Capture22222-1024x223.png" alt="capture22222" width="784" height="171" class="wp-image-245 aligncenter" />

&nbsp;

<span class="ms-rteFontFace-12 ms-rteThemeForeColor-5-4">7. Copy the client id and save it somewhere.</span>

<span class="ms-rteFontFace-12 ms-rteThemeForeColor-5-4">               <img src="https://msdnshared.blob.core.windows.net/media/2016/11/Capture53.png" alt="capture5" width="505" height="57" class="wp-image-105 size-full aligncenter" /></span>

&nbsp;

<span class="ms-rteFontFace-12 ms-rteThemeForeColor-5-4">8. </span><span class="ms-rteFontFace-12 ms-rteThemeForeColor-5-4">Change the reply URL to  </span><a href="https://getpostman.com/oauth2/callback"><span>https://getpostman.com/oauth2/callback</span></a><span class="ms-rteFontFace-12 ms-rteThemeForeColor-5-4">which you see in post man as callback  URL. </span>

<img src="https://msdnshared.blob.core.windows.net/media/2016/11/Capture72.png" alt="capture7" width="629" height="127" class="wp-image-115 size-full aligncenter" />

&nbsp;

<span class="ms-rteFontFace-12 ms-rteThemeForeColor-5-4">9. Generate keys and save it somewhere safely. </span>

<span class="ms-rteThemeForeColor-5-4 ms-rteFontFace-12">Note : <span>The keys will be generated after selecting the duration and clicking on save button and it needs to be saved as you won't be able to retrieve the key value after you leave the page</span>. The keys will be used as client  secret while generating the token.</span>

<img src="https://msdnshared.blob.core.windows.net/media/2016/11/Capture82.png" alt="capture8" width="557" height="150" class="wp-image-125 size-full aligncenter" />

&nbsp;

<span class="ms-rteFontFace-12 ms-rteThemeForeColor-5-4">10. Add the necessary permission by clicking on Add application -&gt; Add Windows Azure Service Management API and specify the Access Azure service management as Organization permission as explained in steps below and save the changes.</span>

<img src="https://msdnshared.blob.core.windows.net/media/2016/11/Capture92.png" alt="capture9" width="630" height="736" class="wp-image-135 size-full aligncenter" />

&nbsp;

<span class="ms-rteThemeForeColor-5-4 ms-rteFontFace-12">11. This completes the configuration changes required. Now click on view end points and copy the Auth and token URL's</span>

</div>
<img src="https://msdnshared.blob.core.windows.net/media/2016/11/Capture102.png" alt="capture10" width="603" height="438" class="wp-image-136 aligncenter" />

&nbsp;
<div class="ms-rte-layoutszone-inner">

<span class="ms-rteThemeForeColor-5-4 ms-rteFontFace-12">12. Please have the following information handy before we generate the Access token from post man.</span>

</div>
</div>
<img src="https://msdnshared.blob.core.windows.net/media/2016/11/Capture112.png" alt="capture11" width="477" height="410" class="wp-image-145 size-full aligncenter" />
<div class="ms-rte-layoutszone-outer">
<div class="ms-rte-layoutszone-inner">

&nbsp;

13. Authorization Endpoint URL (Example= https://login.microsoftonline.com/aaaaaaaa-bbbb-cccc-dddd-                                                      eeeeeeeeeeee/oauth2/authorize<strong>?resource=https://management.azure.com/</strong>)
<ol>
 	<li>Token End point URL-(Example - <a href="https://login.microsoftonline.com/72f988bf-86f1-41af-91ab-2d7cd011db47/oauth2/token">https://login.microsoftonline.com/ aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee /oauth2/token</a>)</li>
 	<li>Client key</li>
 	<li>Client secret</li>
</ol>
Note: Only in the Auth URL, we need to append this string?resource=https://management.azure.com/ as highlighted  above.

<span class="ms-rteFontFace-12 ms-rteThemeForeColor-5-4">14. Launch chrome and post man client, Select Authorization type and OAuth 2.0 and click on get new access token.</span>

</div>
</div>
<img src="https://msdnshared.blob.core.windows.net/media/2016/11/Capture121.png" alt="capture12" width="502" height="226" class="wp-image-155 size-full aligncenter" />

&nbsp;
<div class="ms-rte-layoutszone-outer">
<div class="ms-rte-layoutszone-inner">

<span class="ms-rteFontFace-12 ms-rteThemeForeColor-5-4">15. Feed in the necessary information shown in image and click request token button, While doing so, ensure that Request authorization locally check box is checked.</span>

<img src="https://msdnshared.blob.core.windows.net/media/2016/11/Capture141.png" alt="capture14" width="431" height="437" class="wp-image-165 aligncenter" />

&nbsp;

<span class="ms-rteFontFace-12 ms-rteThemeForeColor-5-4">16. You may be taken into a login window where you have to enter your Azure portal credentials. Post that you will be able to see the generated token name.</span>

<img src="https://msdnshared.blob.core.windows.net/media/2016/11/Capture151.png" alt="capture15" width="537" height="285" class="wp-image-175 size-full aligncenter" />

&nbsp;

<span class="ms-rteThemeForeColor-5-4 ms-rteFontFace-12">17.  Now that you have generated the access/bearer token and you need to use this in the post request. In order to use the token,  click on use token and ensure that in the Add token to dropdown, header is selected.</span>

<img src="https://msdnshared.blob.core.windows.net/media/2016/11/Capture231.png" alt="capture23" width="533" height="285" class="wp-image-185 size-full aligncenter" />

&nbsp;

18. Once, you select use token, note that the count of header changes to 1 indicating that the bearer token generated is getting used

<img src="https://msdnshared.blob.core.windows.net/media/2016/11/Capture241.png" alt="capture24" width="890" height="367" class="wp-image-186 aligncenter" />

&nbsp;

<span class="ms-rteFontFace-12 ms-rteThemeForeColor-5-4">19. Type in the API url into the text box next to post and ensure that POST is selected as we are posting the request here.</span>

<span class="ms-rteThemeForeColor-5-4 ms-rteFontFace-12"> 20. Click on the send button to post the request , Once, post is successful, you will be seeing a message <strong class="ms-rteBackColor-4 ms-rteThemeForeColor-5-4 ms-rteFontFace-12">-                                            {"operation":"ForceFailoverContinuousCopy","startTime":"\/Date(1465905072327)\/"}</strong></span>

</div>
</div></td>
</tr>
</tbody>
</table>]]></content:encoded>
    </item>
    <item>
      <title>Hello world!</title>
      <link>https://docs.microsoft.com/archive/blogs/suhaspv/hello-world</link>
      <pubDate>Mon, 07 Nov 2016 13:00:25 GMT</pubDate>
      <dc:creator><![CDATA[Varsha G]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/suhaspv/?p=1</guid>
      <description><![CDATA[Welcome to Developer Network. This is your first post. Edit or delete it, then start blogging!]]></description>
      <content:encoded><![CDATA[Welcome to <a href="https://blogs.msdn.microsoft.com/">Developer Network</a>. This is your first post. Edit or delete it, then start blogging!]]></content:encoded>
    </item>
  </channel>
</rss>