• Stars
    star
    121
  • Rank 294,022 (Top 6 %)
  • Language
    C#
  • License
    MIT License
  • Created about 5 years ago
  • Updated 9 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A filter which allows a RESTful JSON API client to send requests to .NET web server over HTTP and get proxied to a gRPC service

Grpc-Json Transcoder project

Price version

This is a filter that allows a RESTful JSON API client (Ocelot Gateway) to send requests to .NET Web API (Aggregator Service) over HTTP and get proxied to a gRPC service (on the downstream).

This project is inspired by grpc-gateway which is totally for golang, grpc-dynamic-gateway is for nodejs. And especially, Envoy gRPC-JSON transcoder is the best of transcoding in this area, but it is only on the infrastructure level. You also can use it just like my project used at coolstore-microservices. We might use the approach from Microsoft at GrpcHttpApi, but it is not publish in the official release by Microsoft in the meantime.

gRPC parser borrows the idea from Ocelot.GrpcHttpGateway code-based.

Give a Star!

If you liked GrpcJsonTranscoder project or if it helped you, please give a star for this repository. That will not only help strengthen our .NET community but also improve cloud-native apps development skills for .NET developers in around the world. Thank you very much 👍

Check out my blog or say hi on Twitter!

How to run it!

$ docker-compose up

or

$ bash
$ start.sh # I haven't done it yet :p

In the mean time, we open up the visual studio, run multiple projects included OcelotGateway, AggregationRestApi, ProductCatalogGrpcServer and GreatGrpcServer

Test it as below:

# gRPC
$ curl -X GET -H 'content-type: application/grpc' -k http://localhost:5000/say/Bob
$ {"Message":"Hello Bob"}
# gRPC
$ curl -X GET -H 'content-type: application/grpc' -k http://localhost:5000/products
$ {"Products":[{"Id":1,"Name":"product 1","Quantity":52,"Description":"description of product 1"},...]}
# gRPC
$ curl -X POST -H 'content-type: application/grpc' -d '{ "name": "product 1", "quantity": 1, "description": "this is product 1" }' -k http://localhost:5000/products
$ {"Product":{"Id":915,"Name":"product 1 created","Quantity":1,"Description":"this is product 1 created"}}
# REST Api
$ curl -X GET -H 'content-type: application/json' -k http://localhost:5000/weather 
$ [{"date":"2019-08-17T18:34:41.1090164+07:00","temperatureC":-6,"temperatureF":22,"summary":"Sweltering"},{"date":"2019-08-18T18:34:41.1090371+07:00","temperatureC":27,"temperatureF":80,"summary":"Hot"},{"date":"2019-08-19T18:34:41.1090499+07:00","temperatureC":33,"temperatureF":91,"summary":"Balmy"},{"date":"2019-08-20T18:34:41.1090617+07:00","temperatureC":-14,"temperatureF":7,"summary":"Chilly"},{"date":"2019-08-21T18:34:41.1090743+07:00","temperatureC":22,"temperatureF":71,"summary":"Hot"}]

Notes:

  • REST method: content-type: application/json is for REST method on the downstream services.
  • gRPC method: content-type: application/grpc is really important if you call to gRPC endpoint on the downstream services.

How to understand it!

The project aims to .NET community and its ecosystem which leverage the power of Ocelot Gateway which is very powerful in the gateway components were used by various of companies and sample source code when we try to adopt the microservices architecture project.

That's quite simple with only a few steps to make it work :) Create the .NET Core project with Ocelot in place, then put the configuration as below

{
  "ReRoutes": [
    {
      "UpstreamPathTemplate": "/say/{name}",
      "UpstreamHttpMethod": [ "Get" ],
      "DownstreamPathTemplate": "/Greet.Greeter/SayHello",
      "DownstreamScheme": "http",
      "DownstreamHostAndPorts": [
        {
          "Host": "127.0.0.1",
          "Port": 5003
        }
      ]
    },
    {
      "UpstreamPathTemplate": "/products",
      "UpstreamHttpMethod": [ "Get" ],
      "DownstreamPathTemplate": "/ProductCatalog.Product/GetProducts",
      "DownstreamScheme": "http",
      "DownstreamHostAndPorts": [
        {
          "Host": "127.0.0.1",
          "Port": 5002
        }
      ]
    },
    {
      "UpstreamPathTemplate": "/products",
      "UpstreamHttpMethod": [ "Post" ],
      "DownstreamPathTemplate": "/ProductCatalog.Product/CreateProduct",
      "DownstreamScheme": "http",
      "DownstreamHostAndPorts": [
        {
          "Host": "127.0.0.1",
          "Port": 5002
        }
      ]
    },
    {
      "UpstreamPathTemplate": "/weather",
      "UpstreamHttpMethod": [ "Get" ],
      "DownstreamPathTemplate": "/weatherforecast",
      "DownstreamScheme": "http",
      "DownstreamHostAndPorts": [
        {
          "Host": "localhost",
          "Port": 5001
        }
      ]
    }
  ],
  "GlobalConfiguration": {
  }
}

Then in code Program.cs, you only put a few line

var configuration = new OcelotPipelineConfiguration
{
    PreQueryStringBuilderMiddleware = async (ctx, next) =>
    {
        await ctx.HandleGrpcRequestAsync(next);
    }
};

app.UseOcelot(configuration).Wait();

Don't believe what I said. Try it!

We haven't tested it with stream and full-duplex transport protocols yet. So we feel free to contribute by the .NET community.

Contributing

  1. Fork it!
  2. Create your feature branch: git checkout -b my-new-feature
  3. Commit your changes: git commit -am 'Add some feature'
  4. Push to the branch: git push origin my-new-feature
  5. Submit a pull request :p

More Repositories

1

awesome-dotnet-core

🐝 A collection of awesome .NET core libraries, tools, frameworks and software
C#
18,711
star
2

clean-code-dotnet

🛁 Clean Code concepts and tools adapted for .NET
C#
6,204
star
3

go-coffeeshop

☕ A practical event-driven microservices demo built with Golang. Nomad, Consul Connect, Vault, and Terraform for deployment
Go
4,110
star
4

clean-architecture-dotnet

🕸 Yet Another .NET Clean Architecture, but for Microservices project. It uses Minimal Clean Architecture with DDD-lite, CQRS-lite, and just enough Cloud-native patterns apply on the simple eCommerce sample and run on Tye with Dapr extension 🍻
C#
1,229
star
5

blog-core

Modular blog using Blazor with clean domain-driven design patterns
CSS
393
star
6

practical-dapr

A full-stack .NET microservices build on Dapr and Tye
C#
301
star
7

practical-dotnet-aspire

The practical .NET Aspire builds on the coffeeshop app business domain
C#
250
star
8

northwind-dotnet

A full-stack .NET 6 Microservices build on Minimal APIs and C# 10
C#
182
star
9

magazine-website

🐭 A magazine website (using .NET Core, ASP.NET Core, EF Core) with DDD, CQRS, microservices, asynchronous programming applied...
C#
169
star
10

webassembly-tour

⚙️ Take you through a tour of WebAssembly (WASM targets on WASI) with wasmCloud, Krustlet, WAGI, etc. 🌟 Give it a star if you like it.
Rust
149
star
11

coffeeshop-on-nomad

The .NET coffeeshop application runs on Docker, Nomad and Consul Connect
C#
108
star
12

shopping-cart-k8s

Service Mesh patterns for Microservices
C#
62
star
13

ShoppingCartDemo

The demo using MSA approach with .NET Core stack
C#
61
star
14

practical-opentelemetry

Make OpenTelemetry works on .NET Core with features such as tracing, logs and metrics on multiple protocols like HTTP/gRPC/UDP/TCP...
C#
59
star
15

bff-auth

The demonstration of modern authentication using BFF pattern and authorization enforcer using OPA
C#
51
star
16

coffeeshop-modular

.NET coffee shop application with modular approach
C#
47
star
17

magazine-website-mvc-5

A magazine website that implemented using ASP.NET MVC 5, Web API 2 and AngularJs
JavaScript
46
star
18

dapr-labs

Many forms of coffeeshop implemented by C# and Rust run on WebAssembly/WASI (Spin) + Dapr. ⭐️ Star to support our work!
C#
43
star
19

coffeeshop-on-dapr

The coffeeshop event-driven application is developed in C# and runs on Dapr (AKS)
C#
36
star
20

magazine-website-akka

The experiment on the akkadotnet
C#
23
star
21

coffeeshop-dapr-workflow

Opinionated coffeeshop application builds with Dapr workflow
C#
23
star
22

coolstore-moduliths

The coolstore website on modular monolith approach
C#
19
star
23

practical-cqrs-es

This repo contains all CQRS and ES with Clean Architecture on .NET Core
C#
16
star
24

modular-starter-kit

The starter kit with entire modular approach to help remove boilerplate code in developing
C#
15
star
25

fernet-dotnet

Fernet generates and verifies HMAC-based authentication tokens
C#
14
star
26

thangchung

11
star
27

thangchung.github.io

:trollface: thangchung zone
CSS
10
star
28

MessageBusLite

The lightweight version of message bus (event + command) on the .NET Core
C#
9
star
29

minimal-apis-csharp10

C# 10 and Minimal APIs demo for Vietnam .NET Conf 2021
C#
7
star
30

actix-dapr-rs

Make dapr-rs working with actix-web better
Rust
6
star
31

northwind-rs

The northwind application with the clean architecture approach powered by Rust
Rust
6
star
32

branca-dotnet

Authenticated and encrypted API tokens using modern crypto
C#
6
star
33

cinema-booking

Cinema Booking Application
JavaScript
5
star
34

todo-bicep

C#
5
star
35

authentication-authorization-dotnetcore-course

Authentication & Authorization in ASP.NET Core 2.0 (May 2018)
C#
4
star
36

tailwindonblazor-template

Makes Tailwind works with Blazor (live-reload mode)
C#
4
star
37

dapr-actors-experiment

This is an experiment that use Dapr actors on booking movie scenario
C#
4
star
38

todo-dotnet6

This is todo app on .NET 6 and deploy to Heroku
C#
4
star
39

presentations

My presentation slides and content
3
star
40

NUnit2Report

Export a report for NUnit framework
C#
3
star
41

NHibernate3Sample

The short example that wrote in NHibernate 3 Alpha 2, Fluent NHibernate, Autofac,...
3
star
42

owasp-quiz

The set of OWASP quiz
JavaScript
3
star
43

netcorelibs

The .NET Core best practices and tips for booting up the project development.
JavaScript
3
star
44

elm-quizzer

Quizzer Application
Elm
2
star
45

todo-atmos

Todo application on Atmos (WebAssembly with WASI)
Rust
2
star
46

graphql4net

The simple GraphQL for .NET developers.
C#
2
star
47

ConfORMSample

Using ConfORM for entity mappings and made mutiple database instances for SessionFactory management.
C#
2
star
48

magazine-website-lite

JavaScript
2
star
49

footballdata

C#
2
star
50

practical-dotnet-with-cna

C#
1
star
51

football-scores-lite

The run-time live football scores system
JavaScript
1
star
52

pocket-movies

Personal pocket movies that consume Rotten Tomatoes API for searching movies.
C#
1
star
53

gprc-blog

The modern blog totally builds with gRPC protocol
1
star
54

yew-parceljs

📦 The experiment web application builds with Yew (WebAssembly framework on Rust) + Tailwind and Parceljs v2
Rust
1
star
55

fermyon-vagrant-box

Vagrant box that contains Docker, Nomad, Consul, Spin to get starting with fermyon platform
1
star
56

coffeeshop-on-spinkube

1
star