-
Notifications
You must be signed in to change notification settings - Fork 5.9k
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
Conversation
docs/azure/sdk/snippets/protocol-convenience-methods/SCMConvenience/Program.cs
Show resolved
Hide resolved
|
||
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>. |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
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.
Summary of changes
dynamic
sample toAzure.Core
protocol methods appSystem.ClientModel
sample apps to latest package versionInternal previews