Microsoft.AspNetCore.Grpc.HttpApi
0.1.0-alpha.20179.2
Prefix Reserved
This package has been deprecated as part of the .NET Package Deprecation effort. You can learn more about it from https://github.com/dotnet/announcements/issues/217
See the version list below for details.
dotnet add package Microsoft.AspNetCore.Grpc.HttpApi --version 0.1.0-alpha.20179.2
NuGet\Install-Package Microsoft.AspNetCore.Grpc.HttpApi -Version 0.1.0-alpha.20179.2
<PackageReference Include="Microsoft.AspNetCore.Grpc.HttpApi" Version="0.1.0-alpha.20179.2" />
paket add Microsoft.AspNetCore.Grpc.HttpApi --version 0.1.0-alpha.20179.2
#r "nuget: Microsoft.AspNetCore.Grpc.HttpApi, 0.1.0-alpha.20179.2"
// Install Microsoft.AspNetCore.Grpc.HttpApi as a Cake Addin #addin nuget:?package=Microsoft.AspNetCore.Grpc.HttpApi&version=0.1.0-alpha.20179.2&prerelease // Install Microsoft.AspNetCore.Grpc.HttpApi as a Cake Tool #tool nuget:?package=Microsoft.AspNetCore.Grpc.HttpApi&version=0.1.0-alpha.20179.2&prerelease
gRPC HTTP API
gRPC HTTP API is an extension for ASP.NET Core that creates RESTful HTTP APIs for gRPC services. Once configured, gRPC HTTP API allows you call gRPC methods with familiar HTTP concepts:
- HTTP verbs
- URL parameter binding
- JSON requests/responses
Of course gRPC can continue to be used as well. RESTful APIs for your gRPC services. No duplication!
Usage
- Add a package reference to
Microsoft.AspNetCore.Grpc.HttpApi
. - Register services in Startup.cs with
AddGrpcHttpApi()
. - Add google/api/http.proto and google/api/annotations.proto files to your project.
- Annotate gRPC methods in your .proto files with HTTP bindings and routes:
syntax = "proto3";
import "google/api/annotations.proto";
package greet;
service Greeter {
rpc SayHello (HelloRequest) returns (HelloReply) {
option (google.api.http) = {
get: "v1/greeter/{name}"
};
}
}
message HelloRequest {
string name = 1;
}
message HelloReply {
string message = 1;
}
The SayHello
gRPC method can now be invoked as gRPC+Protobuf and as an HTTP API:
- Request:
HTTP/1.1 GET /v1/greeter/world
- Response:
{ "message": "Hello world" }
Server logs:
info: Microsoft.AspNetCore.Hosting.Diagnostics[1]
Request starting HTTP/1.1 GET https://localhost:5001/v1/greeter/world
info: Microsoft.AspNetCore.Routing.EndpointMiddleware[0]
Executing endpoint 'gRPC - v1/greeter/{name}'
info: Server.GreeterService[0]
Sending hello to world
info: Microsoft.AspNetCore.Routing.EndpointMiddleware[1]
Executed endpoint 'gRPC - v1/greeter/{name}'
info: Microsoft.AspNetCore.Hosting.Diagnostics[2]
Request finished in 1.996ms 200 application/json
This is a simple example. See HttpRule for more customization options.
Currently Microsoft.AspNetCore.Grpc.HttpApi
is not published to NuGet.org and is instead available on a custom NuGet feed. Follow instructions for setting up the custom NuGet feed in your solution.
gRPC Gateway
grpc-gateway maps RESTful HTTP APIs to gRPC using a proxy server. This project adds the same features as grpc-gateway but without a proxy.
Known issues
Protobuf JSON serialization uses the JSON support in Google.Protobuf
Issues with this JSON implementation:
- It's blocking (i.e. not async), which requires the input and output to be cached in memory so as not to block ASP.NET Core.
- It's not optimized for performance.
Improvement would be to write a new runtime serializer for protobuf types with the same behavior. It would be async, use System.Text.Json
and cache necessary reflection. An alternative approach would be to write a protoc
plugin that generates the JSON serialization code.
google/api/annotations.proto
and google/api/http.proto
need to be added to source code
google/api/annotations.proto
and google/api/http.proto
need to be added in the end-user's source code so the Protobuf compiler can load them along with the user's proto files. It would be a nicer developer experience if the user somehow didn't need to worry about those files.
NuGet feed
The Microsoft.AspNetCore.Grpc.HttpApi
package is published at https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet5/nuget/v3/index.json
To use this NuGet repository and get the latest package from it, place a NuGet.config
file with the repository setup in your solution folder:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<add key="DotNet5 dev repository" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet5/nuget/v3/index.json" />
</packageSources>
</configuration>
Additional instructions for configuring a project to use a custom NuGet repository are available at Changing NuGet configuration settings.
Experimental project
This project is experimental. It has known issues, it is not complete and it is not supported. We are interested in this technology but there is no commitment to completing it.
We want to gauge developer interest in gRPC HTTP API. If gRPC HTTP API is interesting to you then please give feedback.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
.NET Core | netcoreapp3.0 is compatible. netcoreapp3.1 was computed. |
-
.NETCoreApp 3.0
- Google.Api.CommonProtos (>= 2.0.0-beta01)
- Google.Protobuf (>= 3.11.2)
- Grpc.AspNetCore.Server (>= 2.27.0)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on Microsoft.AspNetCore.Grpc.HttpApi:
Package | Downloads |
---|---|
FCMicroservices
a boilerplate microservice framework |
GitHub repositories (2)
Showing the top 2 popular GitHub repositories that depend on Microsoft.AspNetCore.Grpc.HttpApi:
Repository | Stars |
---|---|
aspnet/AspLabs
Repo for ASP.NET experiments that are not ready for a production release
|
|
aspnet/Benchmarks
Benchmarks for ASP.NET Core
|
Version | Downloads | Last updated | |
---|---|---|---|
0.1.0-alpha.21317.5 | 593,103 | 6/18/2021 | |
0.1.0-alpha.20580.2 | 87,445 | 11/30/2020 | |
0.1.0-alpha.20305.2 | 80,904 | 6/5/2020 | |
0.1.0-alpha.20179.2 | 5,147 | 3/30/2020 |