Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add dynamic data sample with protocol methods #42351

Merged
merged 7 commits into from
Aug 28, 2024

Conversation

scottaddie
Copy link
Member

@scottaddie scottaddie commented Aug 27, 2024

Summary of changes

  • Add dynamic sample to Azure.Core protocol methods app
  • Update OpenAI System.ClientModel sample apps to latest package version
  • Edit pass on associated doc, including conversion to xref links for API ref pages

Internal previews

📄 File 🔗 Preview link
docs/azure/sdk/protocol-convenience-methods.md docs/azure/sdk/protocol-convenience-methods

@dotnet-bot dotnet-bot added this to the August 2024 milestone Aug 27, 2024
@scottaddie scottaddie merged commit 81ef6ac into main Aug 28, 2024
8 checks passed
@scottaddie scottaddie deleted the scottaddie/protocol-method-sample branch August 28, 2024 15:18

The preceding code demonstrates the following protocol method patterns:

- Uses the `RequestContent` type to supply data for the request body.
- Uses the `RequestContext` type to configure request options.
- Returns data using the `Response` type.
- Reads `response.Content` to access the response data.
- Reads content from the response data into a [dynamic](../../csharp/advanced-topics/interop/using-type-dynamic.md) type using <xref:Azure.AzureCoreExtensions.ToDynamicFromJson%2A>.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be preferable to link this blog post: https://devblogs.microsoft.com/azure-sdk/dynamic-json-in-azure-core/
It will give more context about the intended use and capabilities of the dynamic instance returned from ToDynamicFromJson.

}

dynamic content = response.Content.ToDynamicFromJson(JsonPropertyNames.CamelCase);
Copy link
Member

@annelo-msft annelo-msft Aug 28, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be helpful to add a comment here with a short explanation that the dynamic instance returned from ToDynamicFromJson lets you use response content like a convenience model, which helps you evolve code from protocol to convenience with minimal code changes as convenience APIs are added to libraries.

new RequestOptions
{
ErrorOptions = ClientErrorBehaviors.NoThrow,
});

PipelineResponse response = result.GetRawResponse();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be worth noting here that you can still call ToDynamicFromJson with SCM-based responses if desired. This API lives in Azure.Core so an app would need to reference this package, but nothing prevents someone from mixing Azure and unbranded code from an application usage perspective -- in fact, it is expected that people will do this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants