|
| 1 | +## Azure DataProtectionClient SDK for JavaScript |
| 2 | + |
| 3 | +This package contains an isomorphic SDK for DataProtectionClient. |
| 4 | + |
| 5 | +### Currently supported environments |
| 6 | + |
| 7 | +- Node.js version 6.x.x or higher |
| 8 | +- Browser JavaScript |
| 9 | + |
| 10 | +### How to Install |
| 11 | + |
| 12 | +```bash |
| 13 | +npm install @azure/arm-dataprotectionplatform |
| 14 | +``` |
| 15 | + |
| 16 | +### How to use |
| 17 | + |
| 18 | +#### nodejs - client creation and getResourcesInSubscription backupVaults as an example written in TypeScript. |
| 19 | + |
| 20 | +##### Install @azure/ms-rest-nodeauth |
| 21 | + |
| 22 | +- Please install minimum version of `"@azure/ms-rest-nodeauth": "^3.0.0"`. |
| 23 | +```bash |
| 24 | +npm install @azure/ms-rest-nodeauth@"^3.0.0" |
| 25 | +``` |
| 26 | + |
| 27 | +##### Sample code |
| 28 | + |
| 29 | +While the below sample uses the interactive login, other authentication options can be found in the [README.md file of @azure/ms-rest-nodeauth](https://www.npmjs.com/package/@azure/ms-rest-nodeauth) package |
| 30 | +```typescript |
| 31 | +const msRestNodeAuth = require("@azure/ms-rest-nodeauth"); |
| 32 | +const { DataProtectionClient } = require("@azure/arm-dataprotectionplatform"); |
| 33 | +const subscriptionId = process.env["AZURE_SUBSCRIPTION_ID"]; |
| 34 | + |
| 35 | +msRestNodeAuth.interactiveLogin().then((creds) => { |
| 36 | + const client = new DataProtectionClient(creds, subscriptionId); |
| 37 | + client.backupVaults.getResourcesInSubscription().then((result) => { |
| 38 | + console.log("The result is:"); |
| 39 | + console.log(result); |
| 40 | + }); |
| 41 | +}).catch((err) => { |
| 42 | + console.error(err); |
| 43 | +}); |
| 44 | +``` |
| 45 | + |
| 46 | +#### browser - Authentication, client creation and getResourcesInSubscription backupVaults as an example written in JavaScript. |
| 47 | + |
| 48 | +##### Install @azure/ms-rest-browserauth |
| 49 | + |
| 50 | +```bash |
| 51 | +npm install @azure/ms-rest-browserauth |
| 52 | +``` |
| 53 | + |
| 54 | +##### Sample code |
| 55 | + |
| 56 | +See https://github.com/Azure/ms-rest-browserauth to learn how to authenticate to Azure in the browser. |
| 57 | + |
| 58 | +- index.html |
| 59 | +```html |
| 60 | +<!DOCTYPE html> |
| 61 | +<html lang="en"> |
| 62 | + <head> |
| 63 | + <title>@azure/arm-dataprotectionplatform sample</title> |
| 64 | + <script src="node_modules/@azure/ms-rest-js/dist/msRest.browser.js"></script> |
| 65 | + <script src="node_modules/@azure/ms-rest-azure-js/dist/msRestAzure.js"></script> |
| 66 | + <script src="node_modules/@azure/ms-rest-browserauth/dist/msAuth.js"></script> |
| 67 | + <script src="node_modules/@azure/arm-dataprotectionplatform/dist/arm-dataprotectionplatform.js"></script> |
| 68 | + <script type="text/javascript"> |
| 69 | + const subscriptionId = "<Subscription_Id>"; |
| 70 | + const authManager = new msAuth.AuthManager({ |
| 71 | + clientId: "<client id for your Azure AD app>", |
| 72 | + tenant: "<optional tenant for your organization>" |
| 73 | + }); |
| 74 | + authManager.finalizeLogin().then((res) => { |
| 75 | + if (!res.isLoggedIn) { |
| 76 | + // may cause redirects |
| 77 | + authManager.login(); |
| 78 | + } |
| 79 | + const client = new Azure.ArmDataprotectionplatform.DataProtectionClient(res.creds, subscriptionId); |
| 80 | + client.backupVaults.getResourcesInSubscription().then((result) => { |
| 81 | + console.log("The result is:"); |
| 82 | + console.log(result); |
| 83 | + }).catch((err) => { |
| 84 | + console.log("An error occurred:"); |
| 85 | + console.error(err); |
| 86 | + }); |
| 87 | + }); |
| 88 | + </script> |
| 89 | + </head> |
| 90 | + <body></body> |
| 91 | +</html> |
| 92 | +``` |
| 93 | + |
| 94 | +## Related projects |
| 95 | + |
| 96 | +- [Microsoft Azure SDK for Javascript](https://github.com/Azure/azure-sdk-for-js) |
| 97 | + |
| 98 | + |
0 commit comments