Security News
Fluent Assertions Faces Backlash After Abandoning Open Source Licensing
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
@azure-rest/core-client
Advanced tools
Core library for interfacing with AutoRest rest level generated code
@azure-rest/core-client is a core library for building Azure SDKs using the REST client. It provides essential functionalities for making HTTP requests, handling responses, and managing client configurations. This package is designed to be used as a foundational component for other Azure SDK libraries.
Creating a REST Client
This feature allows you to create a REST client instance that can be used to interact with Azure services. The `createClient` function initializes the client with a base URL.
const { createClient } = require('@azure-rest/core-client');
const client = createClient('https://example.azure.com');
Making GET Requests
This feature demonstrates how to make a GET request to a specified path using the REST client. The response body is then logged to the console.
const response = await client.path('/resource').get();
console.log(response.body);
Making POST Requests
This feature shows how to make a POST request with a JSON body. The response body is then logged to the console.
const response = await client.path('/resource').post({ body: { key: 'value' } });
console.log(response.body);
Handling Responses
This feature demonstrates how to handle responses from the REST client. It checks the status code and logs either a success message with the response body or an error message with the status code.
const response = await client.path('/resource').get();
if (response.status === 200) {
console.log('Success:', response.body);
} else {
console.log('Error:', response.status);
}
Configuring Client Options
This feature shows how to configure client options such as headers when creating a REST client instance. In this example, an Authorization header is added to the client.
const { createClient } = require('@azure-rest/core-client');
const client = createClient('https://example.azure.com', { headers: { 'Authorization': 'Bearer token' } });
Axios is a popular promise-based HTTP client for the browser and Node.js. It provides similar functionalities for making HTTP requests and handling responses. Compared to @azure-rest/core-client, Axios is more general-purpose and not specifically tailored for Azure services.
Node-fetch is a lightweight module that brings `window.fetch` to Node.js. It is used for making HTTP requests and handling responses. While it offers similar functionalities, it lacks the built-in Azure-specific configurations and utilities provided by @azure-rest/core-client.
Request is a simplified HTTP client for Node.js with support for various HTTP methods and options. It is similar to @azure-rest/core-client in terms of making HTTP requests, but it is not specifically designed for Azure SDKs and is now deprecated in favor of more modern alternatives.
This library is primarily intended to be used in code generated by AutoRest and autorest.typescript
. Specifically for rest level clients
See our support policy for more details.
This package is primarily used in generated code and not meant to be consumed directly by end users.
Examples can be found in the samples
folder.
You can build and run the tests locally by executing rushx test
. Explore the test
folder to see advanced usage and behavior of the public classes.
Learn more about AutoRest and the autorest.typescript extension for generating a compatible client on top of this package.
If you run into issues while using this library, please feel free to file an issue.
If you'd like to contribute to this library, please read the contributing guide to learn more about how to build and test the code.
FAQs
Core library for interfacing with Azure Rest Clients
The npm package @azure-rest/core-client receives a total of 167,024 weekly downloads. As such, @azure-rest/core-client popularity was classified as popular.
We found that @azure-rest/core-client demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
Research
Security News
Socket researchers uncover the risks of a malicious Python package targeting Discord developers.
Security News
The UK is proposing a bold ban on ransomware payments by public entities to disrupt cybercrime, protect critical services, and lead global cybersecurity efforts.