Microsoft.AspNetCore.Grpc.HttpApi
0.1.0-alpha.20179.2
Prefix Reserved
Microsoft.AspNetCore.Grpc.JsonTranscoding
Additional DetailsThis package is deprecated and no longer maintained. Please use Microsoft.AspNetCore.Grpc.JsonTranscoding instead.
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" />
<PackageVersion Include="Microsoft.AspNetCore.Grpc.HttpApi" Version="0.1.0-alpha.20179.2" />
<PackageReference Include="Microsoft.AspNetCore.Grpc.HttpApi" />
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"
#:package Microsoft.AspNetCore.Grpc.HttpApi@0.1.0-alpha.20179.2
#addin nuget:?package=Microsoft.AspNetCore.Grpc.HttpApi&version=0.1.0-alpha.20179.2&prerelease
#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. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.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 (2)
Showing the top 2 NuGet packages that depend on Microsoft.AspNetCore.Grpc.HttpApi:
| Package | Downloads |
|---|---|
|
FCMicroservices
a boilerplate microservice framework |
|
|
Yyt.Abp.HkSdk.Grpc.Server
it is a library that provides the functionality to encapsulate the Hikvision SDK (hksdk) protocol as a gRPC server service for .NET applications. Built with a modular architecture, it enables seamless integration into your existing projects.Maintained and supported by Patrick.Z, it streamlines routine development configurations in .NET applications and takes over heavy, tedious workloads for you. |
GitHub repositories (1)
Showing the top 1 popular GitHub repositories that depend on Microsoft.AspNetCore.Grpc.HttpApi:
| Repository | Stars |
|---|---|
|
aspnet/Benchmarks
Benchmarks for ASP.NET Core
|
| Version | Downloads | Last Updated | |
|---|---|---|---|
| 0.1.0-alpha.21317.5 | 919,497 | 6/18/2021 | |
| 0.1.0-alpha.20580.2 | 101,818 | 11/30/2020 | |
| 0.1.0-alpha.20305.2 | 81,352 | 6/5/2020 | |
| 0.1.0-alpha.20179.2 | 6,019 | 3/30/2020 |