What is @azure/ms-rest-js?
@azure/ms-rest-js is a package provided by Microsoft Azure that offers a set of tools for making HTTP requests and handling responses, particularly for Azure services. It includes features for authentication, serialization, and deserialization of data, and provides a foundation for building SDKs for Azure services.
What are @azure/ms-rest-js's main functionalities?
HTTP Client
The HTTP Client feature allows you to send HTTP requests and handle responses. This is useful for interacting with RESTful APIs.
const { HttpClient } = require('@azure/ms-rest-js');
const client = new HttpClient();
client.sendRequest({ url: 'https://example.com', method: 'GET' }).then(response => {
console.log(response.bodyAsText);
});
Authentication
The Authentication feature provides support for various authentication mechanisms, such as token-based authentication, which is essential for securely accessing Azure services.
const { TokenCredentials } = require('@azure/ms-rest-js');
const credentials = new TokenCredentials('your-access-token');
const client = new HttpClient(credentials);
client.sendRequest({ url: 'https://example.com', method: 'GET' }).then(response => {
console.log(response.bodyAsText);
});
Serialization and Deserialization
The Serialization and Deserialization feature allows you to convert JavaScript objects to and from JSON, which is useful for sending and receiving data in a structured format.
const { Serializer } = require('@azure/ms-rest-js');
const serializer = new Serializer();
const model = { name: 'example', age: 30 };
const serializedModel = serializer.serialize({ type: { name: 'Composite', className: 'Model', modelProperties: { name: { serializedName: 'name', type: { name: 'String' } }, age: { serializedName: 'age', type: { name: 'Number' } } } } }, model);
console.log(serializedModel);
Other packages similar to @azure/ms-rest-js
axios
Axios is a popular HTTP client for making requests to APIs. It is similar to the HTTP Client feature of @azure/ms-rest-js but does not include built-in support for Azure-specific authentication or serialization.
request
Request is another HTTP client library for Node.js. It provides a simple way to make HTTP requests but lacks the Azure-specific features such as authentication and serialization found in @azure/ms-rest-js.
node-fetch
Node-fetch is a lightweight module that brings window.fetch to Node.js. It is similar to the HTTP Client feature of @azure/ms-rest-js but does not include Azure-specific functionalities like authentication and serialization.
ms-rest-js
Runtime for isomorphic javascript libraries (that work in the browser and node.js environemnt) generated via Autorest.
Requirements
- node.js version > 6.x
- npm install -g typescript
Installation
- After cloning the repo, execute
npm install
Execution
node.js
- Set the subscriptionId and token
- Run
node samples/node-sample.js
In the browser
- Set the subscriptionId and token and then run
- Open index.html file in the browser. It should show the response from GET request on the storage account. From Chrome type Ctrl + Shift + I and you can see the logs in console.
Architecture Overview
You can find an explanation of how this repository's code works by going to our architecture overview.
Contributing
This project welcomes contributions and suggestions. Most contributions require you to agree to a
Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us
the rights to use your contribution. For details, visit https://cla.microsoft.com.
When you submit a pull request, a CLA-bot will automatically determine whether you need to provide
a CLA and decorate the PR appropriately (e.g., label, comment). Simply follow the instructions
provided by the bot. You will only need to do this once across all repos using our CLA.
This project has adopted the Microsoft Open Source Code of Conduct.
For more information see the Code of Conduct FAQ or
contact opencode@microsoft.com with any additional questions or comments.