{"id":15711,"library":"ms-rest","title":"Azure ms-rest Client Runtime","description":"ms-rest is a foundational client runtime for Node.js client libraries generated using AutoRest, specifically designed for interacting with Azure services. It provides core infrastructure for serialization, deserialization, error handling, tracing, and configuring HTTP client pipelines. The current stable version is 2.5.6, with its last publish in May 2022. While it was a cornerstone of the older Azure SDK for Node.js, this package and its containing repository (`azure-sdk-for-node`) are now officially deprecated. Newer Azure SDKs (`@azure/*`) leverage more modular core packages like `@azure/core-http` and `@azure/core-rest-pipeline` for improved performance and maintainability. ms-rest ships with built-in TypeScript type definitions and adheres to Microsoft REST API Guidelines for consistent API design and error handling, differentiating it by its specific use within the Azure ecosystem for AutoRest-generated clients.","status":"deprecated","version":"2.5.6","language":"javascript","source_language":"en","source_url":"git@github.com:Azure/azure-sdk-for-node","tags":["javascript","node","microsoft","autorest","clientruntime","typescript"],"install":[{"cmd":"npm install ms-rest","lang":"bash","label":"npm"},{"cmd":"yarn add ms-rest","lang":"bash","label":"yarn"},{"cmd":"pnpm add ms-rest","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"While CommonJS `require` is common for older Node.js projects using ms-rest, ESM `import` is supported for TypeScript and modern JavaScript environments.","wrong":"const msRest = require('ms-rest'); const serialized = msRest.serialize(...);","symbol":"serialize","correct":"import { serialize } from 'ms-rest';"},{"note":"For `deserialize` operations, ensure the mapper definition accurately reflects the expected structure of the incoming data to avoid runtime type errors.","wrong":"const msRest = require('ms-rest'); const deserialized = msRest.deserialize(...);","symbol":"deserialize","correct":"import { deserialize } from 'ms-rest';"},{"note":"ServiceClient is the base class for AutoRest-generated clients, extending it is more common than direct instantiation.","wrong":"const ServiceClient = require('ms-rest').ServiceClient;","symbol":"ServiceClient","correct":"import { ServiceClient } from 'ms-rest';"}],"quickstart":{"code":"import { serialize, deserialize } from 'ms-rest';\n\ninterface Product {\n  id: number;\n  name: string;\n  price?: number;\n}\n\nconst productMapper = {\n  type: {\n    name: 'Composite',\n    className: 'Product',\n    modelProperties: {\n      id: {\n        required: true,\n        serializedName: 'id',\n        type: { name: 'Number' }\n      },\n      name: {\n        required: true,\n        serializedName: 'productName',\n        type: { name: 'String' }\n      },\n      price: {\n        required: false,\n        serializedName: 'productPrice',\n        type: { name: 'Number' }\n      }\n    }\n  }\n};\n\nconst originalProduct: Product = { id: 1, name: 'Example Widget', price: 99.99 };\n\n// Serialize an object based on the defined mapper\nconst serializedProduct = serialize(productMapper, originalProduct, 'productObject');\n\nconsole.log('Original Product:', originalProduct);\nconsole.log('Serialized Product:', JSON.stringify(serializedProduct, null, 2));\n\n// Assuming the serialized form might have different property names on the wire\nconst receivedSerializedProduct = { id: 1, productName: 'Example Widget', productPrice: 99.99 };\n\n// Deserialize the received object back into the Product interface\nconst deserializedProduct = deserialize(productMapper, receivedSerializedProduct, 'productObject') as Product;\n\nconsole.log('Deserialized Product:', deserializedProduct);\n\n// Example with missing required property (will throw an error during serialization/deserialization)\ntry {\n  const invalidProduct = { name: 'Missing ID' };\n  serialize(productMapper, invalidProduct, 'invalidProduct');\n} catch (error: any) {\n  console.error('\\nError during serialization (expected):', error.message);\n}\n","lang":"typescript","description":"Demonstrates basic object serialization and deserialization using `ms-rest` mappers, including handling required properties during validation."},"warnings":[{"fix":"Migrate to the equivalent services and functionalities provided by the modern `@azure/*` packages. For authentication, use `@azure/identity`. For HTTP pipeline, refer to `@azure/core-rest-pipeline` and `@azure/core-http`.","message":"The entire `azure-sdk-for-node` repository, which includes `ms-rest`, has been deprecated. Users are strongly encouraged to migrate to the new, modular `@azure/*` packages within the `Azure SDK for JavaScript` repository.","severity":"breaking","affected_versions":">=2.0.0"},{"fix":"Carefully review the changelog for specific breaking changes if upgrading within the 2.x range, particularly for HTTP client behavior or request cancellation. Consider migrating to the modern `@azure/core-http` or `@azure/core-rest-pipeline` for up-to-date and consistent HTTP client abstractions.","message":"The related `ms-rest-js` (isomorphic runtime) experienced breaking changes in its v2.0.0 release, notably changing the default HTTP client from `axios` to `node-fetch` and altering `AbortController` behavior. While `ms-rest` is Node.js-specific, this indicates a pattern of significant API shifts across major versions within the broader `ms-rest` family.","severity":"breaking","affected_versions":">=2.0.0"},{"fix":"Replace legacy authentication code that leverages `ms-rest-azure` or `@azure/ms-rest-nodeauth` with credential types and methods provided by `@azure/identity`.","message":"Authentication mechanisms previously handled by `ms-rest-azure` (which depends on `ms-rest`) and `@azure/ms-rest-nodeauth` are deprecated. Modern Azure SDKs use `@azure/identity` for a unified authentication experience.","severity":"deprecated","affected_versions":">=2.0.0"},{"fix":"Ensure consistent module syntax within your project. If using `ms-rest` in a modern ESM project, dynamic `import()` might be required, or configure your build system to correctly transpile/bundle CommonJS modules for ESM consumption. Consider `\"type\": \"module\"` in `package.json` for ESM projects or using `.cjs` for CommonJS files within an ESM project.","message":"Attempting to mix CommonJS `require()` (used by `ms-rest` itself) with ES Modules `import` in a single project can lead to interoperability issues, especially in older Node.js environments or complex module graphs.","severity":"gotcha","affected_versions":"<3.0.0"}],"env_vars":null,"last_verified":"2026-04-21T00:00:00.000Z","next_check":"2026-07-20T00:00:00.000Z","problems":[{"fix":"Import authentication methods from `ms-rest-azure` or `@azure/ms-rest-nodeauth`. For modern applications, migrate to `@azure/identity`. Example: `const msRestAzure = require('ms-rest-azure'); msRestAzure.loginWithServicePrincipalSecret(...)` or `import { DefaultAzureCredential } from '@azure/identity';`","cause":"`ms-rest` itself does not contain authentication methods. These are provided by related packages like `ms-rest-azure` or `@azure/ms-rest-nodeauth`.","error":"TypeError: msRest.loginWithServicePrincipalSecret is not a function"},{"fix":"If consuming `ms-rest` from an ESM context, you may need to use dynamic `import('ms-rest')` or ensure your build system handles CommonJS interoperability. If `ms-rest` is requiring another package that is now ESM-only, you might need to find a CommonJS-compatible version of that dependency or upgrade `ms-rest` if a newer, ESM-compatible version exists (though `ms-rest` itself is deprecated).","cause":"This error occurs when a CommonJS module (like `ms-rest`) attempts to `require()` a package that has transitioned to ES Module format, or when a CommonJS project is trying to run in an environment configured for ESM without proper interop.","error":"ERR_REQUIRE_ESM: Must use import to load ES Module"},{"fix":"Ensure that all properties marked `required: true` in your mapper definitions are present in the JavaScript/TypeScript object you are serializing or deserializing. Check the input object and your mapper definition for consistency.","cause":"`ms-rest` performs validation during serialization and deserialization based on the provided mappers. This error indicates a required property, as defined in the mapper, was missing from the object being processed.","error":"A required property was not provided for type 'MyType'. Property name: 'requiredField'."}],"ecosystem":"npm"}