Skip to content

Commit 8b25176

Browse files
committed
align code with c# sdk samples
1 parent 3968b2e commit 8b25176

File tree

1 file changed

+10
-12
lines changed

1 file changed

+10
-12
lines changed

docs/quickstart/server.mdx

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1502,8 +1502,9 @@ public static class WeatherTools
15021502
HttpClient client,
15031503
[Description("The US state to get alerts for.")] string state)
15041504
{
1505-
var stateData = await client.GetFromJsonAsync<JsonElement>($"/alerts/active/area/{state}");
1506-
var alerts = stateData.GetProperty("features").EnumerateArray();
1505+
using var jsonDocument = await client.ReadJsonDocumentAsync($"/alerts/active/area/{state}");
1506+
var jsonElement = jsonDocument.RootElement;
1507+
var alerts = jsonElement.GetProperty("features").EnumerateArray();
15071508

15081509
if (!alerts.Any())
15091510
{
@@ -1529,16 +1530,13 @@ public static class WeatherTools
15291530
[Description("Latitude of the location.")] double latitude,
15301531
[Description("Longitude of the location.")] double longitude)
15311532
{
1532-
var pointData = await client.GetFromJsonAsync<JsonElement>($"/points/{latitude},{longitude}");
1533-
var forecastUrl = pointData.GetProperty("properties").GetProperty("forecast").GetString();
1534-
1535-
if (string.IsNullOrEmpty(forecastUrl))
1536-
{
1537-
return "Forecast URL not found.";
1538-
}
1539-
1540-
var forecastData = await client.GetFromJsonAsync<JsonElement>(forecastUrl);
1541-
var periods = forecastData.GetProperty("properties").GetProperty("periods").EnumerateArray();
1533+
var pointUrl = string.Create(CultureInfo.InvariantCulture, $"/points/{latitude},{longitude}");
1534+
using var jsonDocument = await client.ReadJsonDocumentAsync(pointUrl);
1535+
var forecastUrl = jsonDocument.RootElement.GetProperty("properties").GetProperty("forecast").GetString()
1536+
?? throw new Exception($"No forecast URL provided by {client.BaseAddress}points/{latitude},{longitude}");
1537+
1538+
using var forecastDocument = await client.ReadJsonDocumentAsync(forecastUrl);
1539+
var periods = forecastDocument.RootElement.GetProperty("properties").GetProperty("periods").EnumerateArray();
15421540

15431541
return string.Join("\n---\n", periods.Select(period => $"""
15441542
{period.GetProperty("name").GetString()}

0 commit comments

Comments
 (0)