npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@zup-it/beagle-web-grpc

v1.0.0

Published

Support gRPC on Beagle Web

Downloads

1

Readme

Beagle WEB gRPC

What is gRPC?


It is an open source framework to perform RPC (Remote call procedure) calls, through the HTTP2 protocol in a two-way streaming format, using Protobufs as interfaces between client and server.

Protobufs, or Protocol Buffers, are a structured data serialization mechanism created by Google, which aim to keep contracts always valid and consistent regarding the implementations that consume a gRPC service.

Proto files, in their content, are very similar to any interface we are used to on the daily basis, but with the .proto extension, where we define which objects and methods are likely to be used in the service's communication.

Learn more...

gRPC for Beagle Web


gRPC is a technology that makes use of the HTTP 2 protocol, however, this technology is not compatible with the current Web structure, so the structure created uses a Client and a CLI, where the CLI is responsible for handling gRPC connections through a Proxy, written with Go, and the Client is responsible for handling all requests made by Beagle to the Proxy.

Requirements


  • Git - CLI: Used internally as a proxy dependency.
  • Go - CLI: Language which the proxy is written.
  • Dep - CLI: Go's dependency manager, where it checks that everything is installed and working as expected.
  • Protoc - CLI: Used by protobufs and necessary for code generation through a .proto file.

Installation


To install the library, install it globally, for a better experience with the CLI, and then install it in your project using the following commands:

npm install -g @zup-it/beagle-web-grpc
npm install --save-dev @zup-it/beagle-web-grpc

or if you use yarn:

yarn global add @zup-it/beagle-web-grpc
yarn add --dev @zup-it/beagle-web-grpc

Getting Started


  1. After installing the library, in the project and globally, create the configuration file in the project's root folder, using: beagle-web-grpc init and then configure the attributes according to your needs.
  2. Then import the gRPC Client:
    • React: ./src/beagle/beagle-service.ts
      import { createBeagleUIService } from '@zup-it/beagle-react'
      import { usingBeagleGrpcClient } from '@zup-it/beagle-web-grpc'
      
      export default createBeagleUIService({
        baseUrl: 'grpc://',
        components: {},
        fetchData: usingBeagleGrpcClient({ proxyAddress: 'http://localhost:8081' })
      })
    • Angular: ./src/app/beagle.module.ts
      import { BeagleModule } from '@zup-it/beagle-angular'
      import { usingBeagleGrpcClient } from '@zup-it/beagle-web-grpc'
      
      @BeagleModule({
        baseUrl: 'grpc://',
        module: {
          path: './beagle-components.module',
          name: 'BeagleComponentsModule',
        },
        components: {},
        fetchData: usingBeagleGrpcClient({ proxyAddress: 'http://localhost:8081' })
      })
      export class Beagle {}
  3. Start your proxy running the following command on the root of the project: beagle-web-grpc start-proxy or beagle-web-grpc spx or beagle-web-grpc start-proxy --mode your-mode.
  4. Use the Beagle Web as usually.

Observations Make sure that your BFF Application is running.

CLI


As gRPC is not compatible with the current structure of the Web, to support the technology, it is necessary to use a Proxy to establish the communication between the REST application and the gRPC Backend application, so we created a CLI (command-line interface), beagle-web-grpc, to facilitate the use of the proxy and provide all the necessary settings.

Available commands for beagle-web-grpc

| Command | Alias | Options | Description | | ------------- | ---------- | ----------- | ------------------------------------------------------------------------------------------------- | | init | i | | Creates the configuration file which define the settings to be used by the Beagle Web gRPC Proxy. | | start-proxy | spx | -m, --mode , set the mode to be used on the configuration file, the default mode is development | Start the gRPC Proxy service, on the port defined in the configuration file, to handle requests between your gRPC server and your application using Beagle Web Frontend (IMPORTANT: You must have all requirements installed) . |

Configuration file ./beagle-grpc.config.json

After running beagle-web-grpc init the file ./beagle-grpc.config.json will be created where the command was executed, generating a file with this content:

{
  "configs": [
    {
      "mode": "development",
      "grpcBackendAddress": "localhost:50051",
      "tlsCertificatePath": "",
      "tlsKeyPath": "",
      "runProxyOnPort": 8081
    },
    {
      "mode": "production",
      "grpcBackendAddress": "https://my-grpc.backend.com/address",
      "tlsCertificatePath": "",
      "tlsKeyPath": "",
      "runProxyOnPort": 8081
    }
  ]
}
Attributes of the configuration file ./beagle-grpc.config.json

| Attribute | Description | | ----------------------- | ----------------------------------------------------------------------------- | | mode | Defines the mode name for the settings to be used when running the gRPC Proxy | | grpcBackendAddress | Defines the address of the backend server that communicates using gRPC. Remembering that all requests that match this route will be redirected to the Proxy | | tlsCertificatePath | Set path to TLS Certificate location | | tlsKeyPath | Set path to TLS Key location | | runProxyOnPort | Defines the Port on which the gRPC Proxy will run |

Client


The gRPC Client for Beagle Web is what redirects grpc requests to the proxy, the client is used through BeagleService in React and the Beagle module in Angular, using the fetchData property, which Beagle allows you to create custom HTTP requests, so the use goes like this:

import { usingBeagleGrpcClient } from '@zup-it/beagle-web-grpc'

// { ... } - your module or service code
{
  // { ... } - other attributes
  fetchData: usingBeagleGrpcClient({ proxyAddress: 'http://localhost:8081' })
}

The gRPC client has the following initialization options (BeagleGrpcClientOptions):

| Attribute | Required? | Default Value | Description | | --------------------- | --------------- | --------------- | ------------------------------------------------------------------------------------- | | proxyAddress | Yes | | Address where the Proxy will be running for the client to communicate with the proxy | | redirectGrpcFrom | No | grpc:// | If this attribute is informed, all requests that the url starts with the informed value will be redirected to the gRPC Proxy, otherwise they will be forwarded normally | | customHttpClient | No | undefined | If this attribute is informed, it will still work as a function to perform custom HTTP requests, however, only if the condition of being a gRPC request is not met |