Microsoft.AspNetCore.Grpc.HttpApi 0.1.0-alpha.20179.2 The ID prefix of this package has been reserved for one of the owners of this package by NuGet.org. Prefix Reserved

.NET Core 3.0
Additional Details

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

This is a prerelease version of Microsoft.AspNetCore.Grpc.HttpApi.
There is a newer prerelease version of this package available.
See the version list below for details.
Install-Package Microsoft.AspNetCore.Grpc.HttpApi -Version 0.1.0-alpha.20179.2
dotnet add 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" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Microsoft.AspNetCore.Grpc.HttpApi --version 0.1.0-alpha.20179.2
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Microsoft.AspNetCore.Grpc.HttpApi, 0.1.0-alpha.20179.2"
#r directive can be used in F# Interactive, C# scripting and .NET Interactive. Copy this into the interactive tool or source code of the script to reference the package.
// 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
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

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!

gRPC loves REST

Usage

  1. Add a package reference to Microsoft.AspNetCore.Grpc.HttpApi.
  2. Register services in Startup.cs with AddGrpcHttpApi().
  3. Add google/api/http.proto and google/api/annotations.proto files to your project.
  4. 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
.NET net5.0 net5.0-windows net6.0 net6.0-android net6.0-ios net6.0-maccatalyst net6.0-macos net6.0-tvos net6.0-windows
.NET Core netcoreapp3.0 netcoreapp3.1
Compatible target framework(s)
Additional computed target framework(s)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (6)

Showing the top 5 NuGet packages that depend on Microsoft.AspNetCore.Grpc.HttpApi:

Package Downloads
Microsoft.AspNetCore.Grpc.Swagger The ID prefix of this package has been reserved for one of the owners of this package by NuGet.org.

Swagger for gRPC ASP.NET Core

SNSApiSharedService

Package Description

NaviSharedService

Package Description

Omnimodus.App.Grpc

Package Description

Lab.GrpcService

Package Description

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 120,116 6/18/2021
0.1.0-alpha.20580.2 44,854 11/30/2020
0.1.0-alpha.20305.2 80,314 6/5/2020
0.1.0-alpha.20179.2 4,295 3/30/2020