Azure 数据表 JS SDK - 如何设置请求标头 - contentType: application/json;odata=nometadata

发布于 2025-01-13 09:53:36 字数 665 浏览 0 评论 0原文

问题:有没有办法设置请求头项 内容类型:application/json;odata=nometadata 在调用 TableClient.listEntities 之前。 目标:接收包含 odata 元数据的整洁的数据有效负载。

我正在使用 Azure 数据表 JavaScript API,并且希望按如下方式指定请求标头项:-

contentType: application/json;odata=nometadata

我已查看文档 (https://learn.microsoft.com/en-us/javascript/api/@azure/data-tables/?view=azure-node-latest),并且有一些方法可以帮助更改请求标头,例如TableInsertEntityHeaders接口包括属性“contentType”。

TableClient.listEntities 方法包含一个参数(选项?:ListTableEntitiesOptions),该参数不包含标头访问。因此,据我所知,API 没有提供明显的功能来更改请求标头。

谢谢

Question: is there a way to set the request header item
contentType: application/json;odata=nometadata
prior to a call to TableClient.listEntities.
Objective: to receive data payloads uncluttered with odata metadata.

I am using the Azure Data Tables JavaScript API, and would like to specify request header item as follows:-

contentType: application/json;odata=nometadata

I've looked through the documentation (https://learn.microsoft.com/en-us/javascript/api/@azure/data-tables/?view=azure-node-latest) and there are some methods which facilitate changes to the request header, e.g. TableInsertEntityHeaders interface includes a property 'contentType'.

the TableClient.listEntities method includes a parameter (options?: ListTableEntitiesOptions) which does not include header access. So, as far as I can see, there is no obvious functionality supplied by the API to change the Request Header.

thank you

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

晨与橙与城 2025-01-20 09:53:36

您可以在查询选项中的 format 参数中指定它。请参阅下面的示例代码:

const { TableClient, AzureNamedKeyCredential } = require("@azure/data-tables");

const account = "account-name";
const accountKey = "account-key";
const tableName = "table-name";

const credential = new AzureNamedKeyCredential(account, accountKey);
const client = new TableClient(`https://${account}.table.core.windows.net`, tableName, credential);

async function main() {
  let entitiesIter = client.listEntities({
    queryOptions: {
      format: "application/json;odata=nometadata"
    }
  });
  let i = 1;
  for await (const entity of entitiesIter) {
    console.log(`Entity ${i}:`);
    console.log(entity);
    console.log('==================');
    i++;
  }
}

main();

You can specify this in format parameter in the query options. Please see the sample code below:

const { TableClient, AzureNamedKeyCredential } = require("@azure/data-tables");

const account = "account-name";
const accountKey = "account-key";
const tableName = "table-name";

const credential = new AzureNamedKeyCredential(account, accountKey);
const client = new TableClient(`https://${account}.table.core.windows.net`, tableName, credential);

async function main() {
  let entitiesIter = client.listEntities({
    queryOptions: {
      format: "application/json;odata=nometadata"
    }
  });
  let i = 1;
  for await (const entity of entitiesIter) {
    console.log(`Entity ${i}:`);
    console.log(entity);
    console.log('==================');
    i++;
  }
}

main();
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文