Skip to content

Commit 9be6e7a

Browse files
committed
add HttpClient extension
1 parent 8b25176 commit 9be6e7a

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

docs/quickstart/server.mdx

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1484,6 +1484,23 @@ When creating the `ApplicationHostBuilder`, ensure you use `CreateEmptyApplicati
14841484
This code sets up a basic console application that uses the Model Context Protocol SDK to create an MCP server with standard I/O transport.
14851485

14861486
### Weather API helper functions
1487+
1488+
Create an extension class for `HttpClient` which helps simplify JSON request handling:
1489+
1490+
```csharp
1491+
using System.Text.Json;
1492+
1493+
internal static class HttpClientExt
1494+
{
1495+
public static async Task<JsonDocument> ReadJsonDocumentAsync(this HttpClient client, string requestUri)
1496+
{
1497+
using var response = await client.GetAsync(requestUri);
1498+
response.EnsureSuccessStatusCode();
1499+
return await JsonDocument.ParseAsync(await response.Content.ReadAsStreamAsync());
1500+
}
1501+
}
1502+
```
1503+
14871504
Next, define a class with the tool execution handlers for querying and converting responses from the National Weather Service API:
14881505

14891506
```csharp

0 commit comments

Comments
 (0)