Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JSON/REST transcoding #167

Open
cwe1ss opened this issue Mar 17, 2019 · 126 comments
Open

JSON/REST transcoding #167

cwe1ss opened this issue Mar 17, 2019 · 126 comments
Assignees
Milestone

Comments

@cwe1ss
Copy link
Contributor

@cwe1ss cwe1ss commented Mar 17, 2019

Hi, first, thanks for all the work you put into this library! I'm really looking forward to using it!!

Are there any plans to support the REST-like HTTP/JSON transcoding (https://cloud.google.com/endpoints/docs/grpc/transcoding ) via the http service annotations?

Having that together with OpenAPI/Swagger is a HUGE help during development when you can just call the API via JSON objects.


2020/01/14 UPDATE: #167 (comment)


2020/04/24 UPDATE:


2020/12/04 UPDATE:

@JamesNK
Copy link
Member

@JamesNK JamesNK commented Mar 17, 2019

No plans to do it for 3.0. Beyond 3.0, it depends on how many people ask for it.

@JunTaoLuo JunTaoLuo added this to the Backlog milestone Mar 19, 2019
@JunTaoLuo
Copy link
Contributor

@JunTaoLuo JunTaoLuo commented Mar 19, 2019

We're keeping this issue open to solicit feedback and see how much demand there exists for this feature.

@jtattermusch
Copy link
Contributor

@jtattermusch jtattermusch commented Mar 22, 2019

FTR, regardless of whether this gets implemented or not, there are multiple proxies that currently offer this functionality:
https://github.com/grpc-ecosystem/grpc-gateway
https://www.envoyproxy.io/docs/envoy/latest/configuration/http_filters/grpc_json_transcoder_filter

@govis
Copy link

@govis govis commented Sep 18, 2019

We need HTTP/JSON to gRPC transcoding so that same plumbing/service can be used to support REST and gRPC clients

@raz-canva
Copy link

@raz-canva raz-canva commented Sep 24, 2019

This would be super helpful to be provided out of the box. As opposed to setting up grpc gateway

@Jonathan34
Copy link

@Jonathan34 Jonathan34 commented Oct 7, 2019

Also interested. We use grpc gateway in golang but need the same functionality in dotnet as we are a big .net consumer.

@bobrot
Copy link

@bobrot bobrot commented Oct 23, 2019

Also interested in this. While there are 3rd party tools that can do this, a simpler implementation is always better.

@Jonathan34
Copy link

@Jonathan34 Jonathan34 commented Oct 23, 2019

if i had to start again, I'd probably use an envoy proxy instead similar to that: https://blog.envoyproxy.io/envoy-and-grpc-web-a-fresh-new-alternative-to-rest-6504ce7eb880
so at least I can have the same solution and transcoding for all the languages

@VladimirLuzhin
Copy link

@VladimirLuzhin VladimirLuzhin commented Jan 13, 2020

That would be very cool since would allow smooth transition from JSON API to GRPC

@Bob9098-source

This comment was marked as off-topic.

@JamesNK
Copy link
Member

@JamesNK JamesNK commented Jan 14, 2020

We have an experimental project that allows JSON/REST with gRPC here: https://github.com/aspnet/AspLabs/tree/master/src/GrpcHttpApi

The README.md at the link has details about how to use it and its status as a project.

@ElderJames
Copy link

@ElderJames ElderJames commented Jan 21, 2020

Looking forward to this feature.

@dashkan
Copy link

@dashkan dashkan commented Feb 20, 2020

Great job!
I think this is a must have for dotnet core framework and tooling. Why proxy gRPC calls when you don't have to. Much more elegant IMO.

@TomDeVree
Copy link

@TomDeVree TomDeVree commented Mar 1, 2020

This is very helpful. Should it be possible to use Swagger (for example Swashbuckle) with this setup? For now it seems it cannot find any operations.

@JamesNK
Copy link
Member

@JamesNK JamesNK commented Mar 30, 2020

There is currently no way to generate Swagger. I think a Swashbuckle extension would need to be created that lets Swashbuckle understand gRPC endpoints and protobuf schemas.

@MedAnd
Copy link

@MedAnd MedAnd commented Apr 1, 2020

Thoughts on support for Azure Functions?

cc @jeffhollan

@Otto404
Copy link

@Otto404 Otto404 commented Apr 15, 2020

impressive. I hope to find these functionalities in production soon

@kollerdroid
Copy link

@kollerdroid kollerdroid commented Apr 21, 2020

Great project. I think GrpcHttpApi should be part of dotnet 5.
Waiting for AuthContext implementation... ;-)

@Dchoksi-brierley
Copy link

@Dchoksi-brierley Dchoksi-brierley commented Jun 4, 2020

The gRPC HTTP API is a great solution - almost every .net application that is adding on gRPC will benefit in maintaining existing external REST interfaces via this solution.
We tried it within our team and it works seamlessly on .net core 3.0. However our application is being implemented using .net core 3.1 - any plans on moving the gRPC HTTP API forward?

@JamesNK
Copy link
Member

@JamesNK JamesNK commented Jun 4, 2020

Does it not work on 3.1?

@alejandrobonillamondragon
Copy link

@alejandrobonillamondragon alejandrobonillamondragon commented Jun 4, 2020

Hi there,
I followed the instructions from
https://www.nuget.org/packages/Microsoft.AspNetCore.Grpc.HttpApi... Installed the pre-release version of Microsoft.AspNetCore.Grpc.HttpApi and Microsoft.AspNetCore.Grpc.Swagger (0.1.0-alpha.20254.1) from NuGet official library. However, when opening swagger UI it says "No operations defined in spec!" and the endpoints are not reachable through HTTP (getting 404)... I'm using .NET Core 3.1, I think a similar issue was already reported here: #745. Do you know if Grpc.Swagger works for 3.1?

This is the Startup.cs

using GrpcGateway.Server;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.OpenApi.Models;

namespace GrpcGateway
{
public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}

    public IConfiguration Configuration { get; }

    // This method gets called by the runtime. Use this method to add services to the container.
    public void ConfigureServices(IServiceCollection services)
    {
        services.AddGrpcHttpApi();

        services.AddSwaggerGen(c =>
        {
            c.SwaggerDoc("v1", new OpenApiInfo { Title = "gRPC HTTP API Example", Version = "v1" });
        });
        services.AddGrpcSwagger();

        //services.AddControllers();
    }

    // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
    public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
    {
        if (env.IsDevelopment())
        {
            app.UseDeveloperExceptionPage();
        }

        app.UseHttpsRedirection();
        app.UseDefaultFiles();
        app.UseStaticFiles();

        app.UseSwagger();
        app.UseSwaggerUI(c =>
        {
            c.SwaggerEndpoint("/swagger/v1/swagger.json", "gRPC HTTP API Example V1");
        });

        app.UseRouting();

        //app.UseAuthorization();

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

}

@Dchoksi-brierley
Copy link

@Dchoksi-brierley Dchoksi-brierley commented Jun 4, 2020

Thanks for the details Alejandro.. James - please let us know if you have any info for us or need any details about the issue. Thanks so much for responding so quickly - much appreciated!

@JamesNK
Copy link
Member

@JamesNK JamesNK commented Jun 5, 2020

It should work in 3.0. I haven't got time to debug this, but feel free to copy the source code for those packages to your machine and step through the code to find out why you get that message.

@Dchoksi-brierley
Copy link

@Dchoksi-brierley Dchoksi-brierley commented Jun 5, 2020

Thanks again for responding back.
We'll debug into the source code - fingers crossed. We were not sure if there were known issues with 3.1 ("Beyond 3.0, it depends on how many people ask for it")... In any case, we'll share what we find - in case it helps any one else.

@JamesNK
Copy link
Member

@JamesNK JamesNK commented Jun 6, 2020

@Dchoksi-brierley
Copy link

@Dchoksi-brierley Dchoksi-brierley commented Jun 6, 2020

Many thanks!!
We were able to make progress - adding a reference to Grpc.AspNetCore.Server and Grpc.Tools made the difference. Those two packages were not required to generate the server stubs in the latest version of Grpc.AspNetCore but looks like they were needed for Microsoft.AspNetCore.Grpc.HttpApi.

@alejandrobonillamondragon
Copy link

@alejandrobonillamondragon alejandrobonillamondragon commented Jun 6, 2020

It works in 3.1. In case this helps someone else. In my case the issue was in the proto files, the Proto folder needs to be placed in the solution's root folder and create a service reference in the project using the main .proto file (the one who imports annotations.proto) marking it to generate the server class. I was placing those files in the project folder and generating the server stub directly from it (without the service reference), in that way it doesn't work.

@Michael-D-Pine-dorsavi
Copy link

@Michael-D-Pine-dorsavi Michael-D-Pine-dorsavi commented Sep 16, 2021

Seriously want this, I am proto typing porting away a large api away into smaller micro services and I want to use Grpc but I probably need to support Http as well at this point in time and this is magnificent.

@drewswiredin
Copy link

@drewswiredin drewswiredin commented Sep 22, 2021

Would love to see these features fully supported. We are moving all of our microservices to gRPC and maintaining HTTP/1.1 accessibility is huge need. But using grpc-ecosystem/grpc-gateway reverse proxies or Envoy's gRPC HTTP/1.1 bridge as a solution is nowhere near as clean and concise as the .NET implementations. We really need full .NET Core support for exposing our gRPC endpoints to HTTP/1.1 clients along with swagger generation. Would be a huge win.

@abinkowski94
Copy link

@abinkowski94 abinkowski94 commented Sep 29, 2021

It looks like an awesome package. Please support it in the future.

@smurphtech
Copy link

@smurphtech smurphtech commented Oct 14, 2021

This was exactly what I was looking for! Please continue to support this package and I look forward to it becoming a full nuget release.

@anispider
Copy link

@anispider anispider commented Oct 30, 2021

Awesome project, I really hope this gets support in the future with a GA one day. I'm already using it in several projects. It's a fantastic "bridge" for proving a way to "move forward" on new technologies while simultaneously allowing legacy tech and project able to communicate with your API. (eg, trying to use a grpc client from PHP or Wordpress is quite painful in my limited experiments).

@ctharris77
Copy link

@ctharris77 ctharris77 commented Nov 1, 2021

Would love to see this become a production viable package

@adelossantos59
Copy link

@adelossantos59 adelossantos59 commented Nov 2, 2021

This is what I'm looking for and hoping that this will be supported soon.

@mikart143
Copy link

@mikart143 mikart143 commented Nov 7, 2021

Would be great to see this as a mature technology in .net. Will definitely help to get rid of wcf

@charlie430
Copy link

@charlie430 charlie430 commented Nov 8, 2021

This looks great, however, streaming responses is important to us.

@marqdouj
Copy link

@marqdouj marqdouj commented Nov 11, 2021

This is the first time I tried this (and saw the article). Love the concept but the article was confusing to me (same issues as others mentioned above about where to put the protos and the missing protos).
I tried to get this to work on VS2022 Current but wouldn't compile - it could not find the proto files (not sure why yet).
In any case, my vote is to make this happen!

@jweschenfelder
Copy link

@jweschenfelder jweschenfelder commented Nov 15, 2021

Very interested in this!!!
Edit: If you are already offering this as Nuget alpha version, I would think that it makes sense to develop it further. As far as I can see, about 105k people have already downloaded the Http Api package, about 35k people have already downloaded the corresponding Swagger package, and some of them will therefore use it.

@pzdouglas
Copy link

@pzdouglas pzdouglas commented Nov 15, 2021

@JamesNK this technology will not enable us create the RESTful APIs if our gRPC services are developed and hosted in Java by another team, is that correct? Thanks!

@biozal
Copy link

@biozal biozal commented Nov 26, 2021

Very interested in this!!!
Edit: If you are already offering this as Nuget alpha version, I would think that it makes sense to develop it further. As far as I can see, about 105k people have already downloaded the Http Api package, about 35k people have already downloaded the corresponding Swagger package, and some of them will therefore use it.

I agree with this. I think it's a great option for backward compatibly to provide the REST bridge to gRPC and it lowers the learning curve and move. Given this - it really needs someone to promote it for someone to even think about using it.

@capetonian
Copy link

@capetonian capetonian commented Nov 27, 2021

This is quite simply one of the most helpful ALPHA projects I've ever seen - thank you!
In a day I've gone from a proto file to a fully fleshed API with documentation, and future proofing my implementation so that when gRPC can be used as the de-facto API there will be little to do.

Very keen to contribute if/when necessary - this is such a needed part of .NET, especially when so many of us API developers are building APIs that simply have to be consumed by others using a variety of languages (which gRPC/protobuf is great for) and yet there will always be a dev team somewhere, coding from the browser, and needing to have a REST or at the very least plain HTTP api.

@JamesNK you've made many hundreds of thousands (if not millions) of developer's lives easier. As the owner of a bespoke software company I just want to say thank you, not just for this awesome project, but all your contributions to the .NET community.

@azrng
Copy link

@azrng azrng commented Nov 29, 2021

look forward to

@chaizhiwen
Copy link

@chaizhiwen chaizhiwen commented Nov 30, 2021

我们将这个问题保持开放以征求反馈意见,看看有多少对这个功能的需求。

如何映射注释

@abimr
Copy link

@abimr abimr commented Nov 30, 2021

This would be really helpful for us. Some languages like R don't have mature gRPC client generation yet.

We need R in our data processing jobs.

@CoryKoehler
Copy link

@CoryKoehler CoryKoehler commented Dec 8, 2021

Any update on if this will be going towards full support?

@JulianBirch
Copy link

@JulianBirch JulianBirch commented Dec 10, 2021

I'll add to the chorus of people saying we'd love this to be fully adopted. It's just too useful to be able to use e.g. SwaggerUI to test out a gRPC endpoint. What I will say is that in its current state, if it doesn't work, it's very hard to figure out what exactly you've done wrong. I can't e.g. assert that an endpoint is present and have it tell me why it isn't.

@sprezzarete
Copy link

@sprezzarete sprezzarete commented Dec 17, 2021

Happy Friday!

I'm re-visiting this and doing a POC to see if I can use in prod. I'm running into 2 issues:

  1. I'm unable to wire nginx to my api gateway. I followed instructions https://docs.microsoft.com/en-us/aspnet/core/host-and-deploy/linux-nginx?view=aspnetcore-6.0#configure-a-reverse-proxy-server but keep on getting a 502
  2. I'm unable to connect from my api gateway to my microservice if the microservice is on a port behind the firewall. I'm using my real ssl cert and using the cert's domain name. I tried adding a host entry to make it resolve to a local IP, but it still doesn't help.

If I can resolve these 2 issues, then I feel pretty comfortable going to prod. I'm considering migrating from java to C#, but may need to rethink that if can't do these fairly straightforward wiring.

Any thoughts @JamesNK ? Much thanks in advance for any support. I have to imagine this is a pretty common scenario, ie nginx reverse proxy to an api gateway (gRPC + your wonderful REST facade) in front of gRPC services.

@beachwalker
Copy link

@beachwalker beachwalker commented Dec 21, 2021

Works really fine for me (got it working net6 services)and I would like to see it as a stable release in the future. Is this support streaming and how?

@enricop
Copy link

@enricop enricop commented Jan 18, 2022

Hi all,
this is an awesome feature to have. Starting both GRPC and JSON WebAPIs from a unique specifications is really usefull.
thanks for this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet