Skip to content

Commit df7c84d

Browse files
authored
Merge pull request #2850 from unoplatform/mergify/bp/release/stable/6.1/pr-2840
docs: fixes for http, kiota and refit pages (backport #2840)
2 parents 0fce1bc + 978267c commit df7c84d

File tree

4 files changed

+31
-43
lines changed

4 files changed

+31
-43
lines changed

doc/Learn/Http/HowTo-Http.md

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,13 @@ When working with a complex application, centralized registration of your API en
1111

1212
### 1. Installation
1313

14-
* Add `HttpRefit` (or `HttpKiota` if using Kiota-generated clients) to the `<UnoFeatures>` property in the Class Library (.csproj) file.
14+
* Add `Http` to the `<UnoFeatures>` property in the Class Library (.csproj) file.
1515

1616
```diff
1717
<UnoFeatures>
1818
Material;
1919
Extensions;
20-
- Http;
21-
+ HttpRefit;
20+
+ Http;
2221
Toolkit;
2322
MVUX;
2423
</UnoFeatures>
@@ -30,9 +29,7 @@ When working with a complex application, centralized registration of your API en
3029

3130
### 2. Enable HTTP
3231

33-
* Call the appropriate method to register a HTTP client with the `IHostBuilder` which implements `IHttpClient`:
34-
* Use .UseHttpRefit() for Refit clients
35-
* Use .UseHttpKiota() for Kiota clients
32+
* Call the `UseHttp()` method to register a HTTP client with the `IHostBuilder` which implements `IHttpClient`:
3633

3734
```csharp
3835
protected override void OnLaunched(LaunchActivatedEventArgs args)
@@ -41,37 +38,34 @@ When working with a complex application, centralized registration of your API en
4138
.Configure(hostBuilder =>
4239
{
4340
hostBuilder.UseHttp();
44-
hostBuilder.UseHttpRefit(); // or UseHttpKiota()
4541
});
4642
...
4743
}
4844
```
4945

5046
### 3. Register Endpoints
5147

52-
* The `AddRefitClient` or `AddKiotaClient` extension method is used to register a client with the service collection when using Refit or Kiota respectively in Uno.Extensions.
48+
* The `AddClient` extension method is used to register a client with the service collection.
5349

54-
* While these extension methods can take a delegate as its argument, the recommended way to configure the HTTP client is to specify a configuration section name. This allows you to configure the added HTTP client using the `appsettings.json` file.
50+
* While the `AddClient()` extension method can take a delegate as its argument, the recommended way to configure the HTTP client is to specify a configuration section name. This allows you to configure the added HTTP client using the `appsettings.json` file.
5551

5652
```csharp
5753
protected override void OnLaunched(LaunchActivatedEventArgs args)
5854
{
5955
var appBuilder = this.CreateBuilder(args)
60-
.Configure(hostBuilder =>
61-
{
62-
hostBuilder.UseHttp(services =>
63-
services.AddRefitClient<IShowService>("ShowService")
64-
// For Kiota:
65-
// hostBuilder.UseHttpKiota(services =>
66-
// services.AddKiotaClient<IShowService>("ShowService")
67-
// );
68-
);
69-
});
56+
.Configure(hostBuilder =>
57+
{
58+
hostBuilder
59+
.UseHttp((context, services) =>
60+
{
61+
services.AddClient<IShowService, ShowService>(context, "ShowService");
62+
});
63+
});
7064
...
7165
}
7266
```
7367

74-
* Ultimately, your service will be based on the functionality provided by the web API, but the `IShowService` interface will be implemented by Refit or Kiota and injected into your application at runtime. You will make requests to the registered endpoint through this interface. In this case, the service interface will look something like this:
68+
* Ultimately, your service will be based on the functionality provided by the web API, but the `HttpClient` associated with it will be injected into the constructor of your service implementation. You will make requests to the registered endpoint inside your service implementation. In this case, the service interface will look something like this:
7569

7670
```csharp
7771
public interface IShowService

doc/Learn/Http/HowTo-Kiota.md

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,15 @@ When working with APIs in your application, having a strongly-typed client can s
2626

2727
### 2. Enable Http in Host Builder
2828

29-
* Add the UseHttpKiota method to the `IHostBuilder`:
29+
* Add the UseHttp method to the `IHostBuilder`:
3030

3131
```csharp
3232
protected override void OnLaunched(LaunchActivatedEventArgs args)
3333
{
3434
var appBuilder = this.CreateBuilder(args)
3535
.Configure(hostBuilder =>
3636
{
37-
hostBuilder.UseHttpKiota();
37+
hostBuilder.UseHttp();
3838
});
3939
...
4040
}
@@ -52,10 +52,9 @@ When working with APIs in your application, having a strongly-typed client can s
5252

5353
```bash
5454
# From a static spec file
55-
kiota generate --openapi PATH_TO_YOUR_API_SPEC.json --language CSharp --class-name MyApiClient --namespace-name MyApp.Client --output ./Client
56-
55+
kiota generate --openapi PATH_TO_YOUR_API_SPEC.json --language CSharp --class-name MyApiClient --namespace-name MyApp.Client.MyApi --output ./MyApp/Content/Client/MyApi
5756
# OR directly from the running server’s Swagger endpoint
58-
kiota generate --openapi http://localhost:5002/swagger/v1/swagger.json --language CSharp --class-name MyApiClient --namespace-name MyApp.Client --output ./Client
57+
kiota generate --openapi http://localhost:5002/swagger/v1/swagger.json --language CSharp --class-name MyApiClient --namespace-name MyApp.Client.MyApi --output ./MyApp/Content/Client/MyApi
5958
```
6059

6160
This will create a client named `MyApiClient` in the Client folder.
@@ -71,7 +70,7 @@ When working with APIs in your application, having a strongly-typed client can s
7170
var appBuilder = this.CreateBuilder(args)
7271
.Configure(hostBuilder =>
7372
{
74-
hostBuilder.UseHttpKiota((context, services) =>
73+
hostBuilder.UseHttp((context, services) =>
7574
services.AddKiotaClient<MyApiClient>(
7675
context,
7776
options: new EndpointOptions { Url = "https://localhost:5002" }

doc/Learn/Http/HowTo-Refit.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ When accessing resources with a [REST-style](https://www.ics.uci.edu/~fielding/p
3535
var appBuilder = this.CreateBuilder(args)
3636
.Configure(hostBuilder =>
3737
{
38-
hostBuilder.UseHttpRefit();
38+
hostBuilder.UseHttp();
3939
});
4040
...
4141
}
@@ -178,7 +178,7 @@ When accessing resources with a [REST-style](https://www.ics.uci.edu/~fielding/p
178178
var appBuilder = this.CreateBuilder(args)
179179
.Configure(hostBuilder =>
180180
{
181-
hostBuilder.UseHttpRefit((context, services) =>
181+
hostBuilder.UseHttp((context, services) =>
182182
services.AddRefitClient<IChuckNorrisEndpoint>(context, httpClient =>
183183
{
184184
httpClient.BaseAddress = new Uri("https://api.chucknorris.io/");
@@ -199,7 +199,7 @@ When accessing resources with a [REST-style](https://www.ics.uci.edu/~fielding/p
199199
var appBuilder = this.CreateBuilder(args)
200200
.Configure(hostBuilder =>
201201
{
202-
hostBuilder.UseHttpRefit((context, services) =>
202+
hostBuilder.UseHttp((context, services) =>
203203
services.AddRefitClient<IChuckNorrisEndpoint>(context)
204204
);
205205
});

doc/Learn/Http/HttpOverview.md

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ For additional documentation on HTTP requests, read the references listed at the
99

1010
## Installation
1111

12-
`HttpRefit` and `HttpKiota` are provided as Uno Features. To enable HTTP client support in your application, add `HttpRefit` or `HttpKiota` to the `<UnoFeatures>` property in the Class Library (.csproj) file.
12+
`Http`, `HttpRefit` and `HttpKiota` are provided as Uno Features. To enable HTTP client support in your application, add `Http`, `HttpRefit` or `HttpKiota` to the `<UnoFeatures>` property in the Class Library (.csproj) file.
1313

1414
[!include[existing-app](../includes/existing-app.md)]
1515

@@ -27,16 +27,11 @@ protected override void OnLaunched(LaunchActivatedEventArgs args)
2727
var builder = this.CreateBuilder(args)
2828
.Configure(host => {
2929
host
30-
.UseHttpRefit((context, services) =>
30+
.UseHttp((context, services) =>
3131
{
3232
services
33-
.AddRefitClient<IShowService>(context, "configsectionname");
33+
.AddClient<IShowService, ShowService>(context, "configsectionname");
3434
});
35-
// or for Kiota:
36-
// host.UseHttpKiota((context, services) =>
37-
// {
38-
// services.AddKiotaClient<MyApiClient>(context, "configsectionname");
39-
// });
4035
});
4136
...
4237
}
@@ -53,10 +48,10 @@ protected override void OnLaunched(LaunchActivatedEventArgs args)
5348
var builder = this.CreateBuilder(args)
5449
.Configure(host => {
5550
host
56-
.UseHttpRefit((context, services) =>
51+
.UseHttp((context, services) =>
5752
{
5853
services
59-
.AddRefitClient<IShowService>(context,
54+
.AddClient<IShowService, ShowService>(context,
6055
new EndpointOptions
6156
{
6257
Url = "https://ch9-app.azurewebsites.net/"
@@ -78,8 +73,8 @@ protected override void OnLaunched(LaunchActivatedEventArgs args)
7873
var appBuilder = this.CreateBuilder(args)
7974
.Configure(hostBuilder =>
8075
{
81-
hostBuilder.UseHttpRefit((ctx, services) => {
82-
services.AddClientWithEndpoint<IShowService, CustomEndpointOptions>();
76+
hostBuilder.UseHttp((ctx, services) => {
77+
services.AddClientWithEndpoint<IShowService, ShowService, CustomEndpointOptions>();
8378
});
8479
});
8580
...
@@ -100,7 +95,7 @@ protected override void OnLaunched(LaunchActivatedEventArgs args)
10095
var builder = this.CreateBuilder(args)
10196
.Configure(host => {
10297
host
103-
.UseHttpRefit((context, services) =>
98+
.UseHttp((context, services) =>
10499
{
105100
services
106101
.AddRefitClient<IChuckNorrisEndpoint>(context);
@@ -133,7 +128,7 @@ protected override void OnLaunched(LaunchActivatedEventArgs args)
133128
var builder = this.CreateBuilder(args)
134129
.Configure(host =>
135130
{
136-
host.UseHttpKiota((context, services) =>
131+
host.UseHttp((context, services) =>
137132
// MyApiClient is generated by Kiota
138133
services.AddKiotaClient<MyApiClient>(
139134
context,

0 commit comments

Comments
 (0)