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
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.
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
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<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
#r "nuget: Microsoft.AspNetCore.Grpc.HttpApi, 0.1.0-alpha.20179.2"
#r directive can be used in F# Interactive and Polyglot Notebooks. 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

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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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 503,636 6/18/2021
0.1.0-alpha.20580.2 79,835 11/30/2020
0.1.0-alpha.20305.2 80,859 6/5/2020
0.1.0-alpha.20179.2 4,938 3/30/2020