Skip to content

Commit

Permalink
update readme (#2183)
Browse files Browse the repository at this point in the history
  • Loading branch information
Varorbc authored Jun 28, 2023
1 parent 83d12ea commit 42cc09e
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 72 deletions.
41 changes: 16 additions & 25 deletions src/Grpc.AspNetCore.Server/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,39 +4,30 @@

## Configure gRPC

In *Startup.cs*:
In *Program.cs*:

* gRPC is enabled with the `AddGrpc` method.
* Each gRPC service is added to the routing pipeline through the `MapGrpcService` method. For information about how to create gRPC services, see [Create gRPC services and methods](https://docs.microsoft.com/aspnet/core/grpc/services).
* Each gRPC service is added to the routing pipeline through the `MapGrpcService` method. For information about how to create gRPC services, see [Create gRPC services and methods](https://learn.microsoft.com/aspnet/core/grpc/services).

```csharp
public class Startup
{
public void ConfigureServices(IServiceCollection services)
{
services.AddGrpc();
}

public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}

app.UseRouting();

app.UseEndpoints(endpoints =>
{
endpoints.MapGrpcService<GreeterService>();
});
}
}
using GrpcGreeter.Services;

var builder = WebApplication.CreateBuilder(args);

// Add services to the container.
builder.Services.AddGrpc();

var app = builder.Build();

// Configure the HTTP request pipeline.
app.MapGrpcService<GreeterService>();

app.Run();
```

ASP.NET Core middleware and features share the routing pipeline, therefore an app can be configured to serve additional request handlers. The additional request handlers, such as MVC controllers, work in parallel with the configured gRPC services.

## Links

* [Documentation](https://docs.microsoft.com/aspnet/core/grpc/aspnetcore)
* [Documentation](https://learn.microsoft.com/aspnet/core/grpc/aspnetcore)
* [grpc-dotnet GitHub](https://github.com/grpc/grpc-dotnet)
43 changes: 21 additions & 22 deletions src/Grpc.AspNetCore.Web/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,32 @@

Grpc.AspNetCore.Web provides middleware that enables ASP.NET Core gRPC services to accept gRPC-Web calls.

In *Startup.cs*:
## Configure gRPC-Web

In *Program.cs*:

```csharp
public void ConfigureServices(IServiceCollection services)
{
services.AddGrpc();
services.AddGrpcWeb(o => o.GrpcWebEnabled = true);
}

public void Configure(IApplicationBuilder app)
{
app.UseRouting();
app.UseGrpcWeb();
app.UseEndpoints(endpoints =>
{
endpoints.MapGrpcService<GreeterService>();
});
}
using GrpcGreeter.Services;

var builder = WebApplication.CreateBuilder(args);

// Add services to the container.
builder.Services.AddGrpc();

var app = builder.Build();

// Configure the HTTP request pipeline.
app.UseRouting();
app.UseGrpcWeb(new GrpcWebOptions { DefaultEnabled = true });
app.MapGrpcService<GreeterService>();

app.Run();
```

gRPC-Web can be enabled for all gRPC services by setting `GrpcWebOptions.GrpcWebEnabled = true`, or enabled on individual services with `EnableGrpcWeb()`:
gRPC-Web can be enabled for all gRPC services by setting `GrpcWebOptions.DefaultEnabled = true`, or enabled on individual services with `EnableGrpcWeb()`:

```csharp
app.UseEndpoints(endpoints =>
{
endpoints.MapGrpcService<GreeterService>().EnableGrpcWeb();
});
app.MapGrpcService<GreeterService>().EnableGrpcWeb();
```

### gRPC-Web and streaming
Expand All @@ -43,5 +42,5 @@ When using gRPC-Web, we only recommend the use of unary methods and server strea

## Links

* [Documentation](https://docs.microsoft.com/aspnet/core/grpc/browser)
* [Documentation](https://learn.microsoft.com/aspnet/core/grpc/browser)
* [grpc-dotnet GitHub](https://github.com/grpc/grpc-dotnet)
41 changes: 16 additions & 25 deletions src/Grpc.AspNetCore/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,39 +8,30 @@

## Configure gRPC

In *Startup.cs*:
In *Program.cs*:

* gRPC is enabled with the `AddGrpc` method.
* Each gRPC service is added to the routing pipeline through the `MapGrpcService` method. For information about how to create gRPC services, see [Create gRPC services and methods](https://docs.microsoft.com/aspnet/core/grpc/services).
* Each gRPC service is added to the routing pipeline through the `MapGrpcService` method. For information about how to create gRPC services, see [Create gRPC services and methods](https://learn.microsoft.com/aspnet/core/grpc/services).

```csharp
public class Startup
{
public void ConfigureServices(IServiceCollection services)
{
services.AddGrpc();
}

public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}

app.UseRouting();

app.UseEndpoints(endpoints =>
{
endpoints.MapGrpcService<GreeterService>();
});
}
}
using GrpcGreeter.Services;

var builder = WebApplication.CreateBuilder(args);

// Add services to the container.
builder.Services.AddGrpc();

var app = builder.Build();

// Configure the HTTP request pipeline.
app.MapGrpcService<GreeterService>();

app.Run();
```

ASP.NET Core middleware and features share the routing pipeline, therefore an app can be configured to serve additional request handlers. The additional request handlers, such as MVC controllers, work in parallel with the configured gRPC services.

## Links

* [Documentation](https://docs.microsoft.com/aspnet/core/grpc/aspnetcore)
* [Documentation](https://learn.microsoft.com/aspnet/core/grpc/aspnetcore)
* [grpc-dotnet GitHub](https://github.com/grpc/grpc-dotnet)

0 comments on commit 42cc09e

Please sign in to comment.