Giter Site home page Giter Site logo

grpc-example's Introduction

gRPC Health Check - TypeScript and JavaScript Example

This repository provides an example of using gRPC with Protobuf in TypeScript and JavaScript for a simple health check service.

The codebase demonstrates how to set up the gRPC server in Go, and how to create TypeScript and JavaScript clients that can interact with it.

There's another example in this repository, where Protobuf is used to serialize messages for use with an MQTT broker. Check out the mqtt branch

Structure

The repository is structured as follows:

  • proto/health/v1/health.proto: This is the protocol buffer definition for the health check service.
  • client-server-ts: This directory contains the TypeScript client and server code.
    • client.ts and server.ts are the main files to look at for seeing how to use the generated code to create a gRPC server and client.
  • client-js: Similar to the TypeScript directory, this contains a JavaScript client for the health check service.
    • grpc.js shows how to use the generated JavaScript code to create a gRPC client.
  • main.go and handlers/health_handler.go: These files set up a simple gRPC server in Go using the protocol buffer definitions.
  • Makefile: This file provides convenient commands for building and running the project.

Getting Started

Before running the examples, ensure that you have Node.js, Go, and buf installed on your machine.

For running the Go server:

  1. Run make serve from the root directory to start the Go gRPC server.

For the TypeScript client:

  1. Navigate to the client-ts directory.
  2. Run buf generate buf.build/djungermann/grpc-example. This fetches the proto files from the remote registry.
  3. Run npm install to install the necessary dependencies.
  4. Make a request to a server using npx tsx grpc.ts
  5. Make a request to a server using npx tsx http.ts

For the JavaScript client:

  1. Navigate to the client-js directory.
  2. Run buf generate buf.build/djungermann/grpc-example. This fetches the proto files from the remote registry.
  3. Run npm install to install the necessary dependencies.
  4. Run node grpc.js to make a request to a server via gRPC.
  5. Run node http.js to make a request to a server via HTTP.

In each case, the client will send a health check request to the server and log the response.

This way, you can run the Go service, and make requests from both Typescript and Javascript. If you update the proto file and push that to Buf, you can try out how to propagate changes, and then implement them in the various examples.

It's also possible to use connect-es to make the HTTP request, but I'll leave that up to the reader to implement

The TypeScript and JavaScript clients demonstrate how to use the protocol buffer messages and service stubs generated from the .proto files to make requests to a gRPC server.

Contributing

Contributions are welcome! Please feel free to submit a pull request.

License

This project is open source under the MIT license. See the LICENSE file for details.

grpc-example's People

Contributors

davidjungermann avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.