An open API service indexing awesome lists of open source software.

https://github.com/soundphilosopher/basic-grpc-service-node

Basic gRPC service written in TypeScript
https://github.com/soundphilosopher/basic-grpc-service-node

cloudevents grpc learning protobuf typescript

Last synced: 3 months ago
JSON representation

Basic gRPC service written in TypeScript

Awesome Lists containing this project

README

          

# 🚀 Basic gRPC Service: The TypeScript Edition

[![TypeScript](https://img.shields.io/badge/TypeScript-007ACC?style=for-the-badge&logo=typescript&logoColor=white)](https://www.typescriptlang.org/)
[![Node.js](https://img.shields.io/badge/Node.js-43853D?style=for-the-badge&logo=node.js&logoColor=white)](https://nodejs.org/)
[![gRPC](https://img.shields.io/badge/gRPC-4285F4?style=for-the-badge&logo=grpc&logoColor=white)](https://grpc.io/)
[![Fastify](https://img.shields.io/badge/Fastify-000000?style=for-the-badge&logo=fastify&logoColor=white)](https://www.fastify.io/)

[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](./LICENSE)
[![Buf](https://img.shields.io/badge/Buf-235BDB?style=flat&logo=buf&logoColor=white)](https://buf.build/)
[![ConnectRPC](https://img.shields.io/badge/ConnectRPC-654FF0?style=flat&logo=connect&logoColor=white)](https://connectrpc.com/)
[![HTTP/2](https://img.shields.io/badge/HTTP%2F2-Enabled-green?style=flat)](https://http2.github.io/)
[![TLS](https://img.shields.io/badge/TLS-Secured-green?style=flat&logo=letsencrypt&logoColor=white)](https://en.wikipedia.org/wiki/Transport_Layer_Security)

> *"Why write boring microservices when you can build something that actually talks back?"*

Welcome to the most entertaining basic gRPC service you'll ever encounter! This isn't just another "Hello World" - it's a fully-featured gRPC service that includes an ELIZA-style therapist, background processing simulation, and all the modern TypeScript/Node.js goodness you crave.

## ✨ What Makes This Special?

🎭 **Three Distinct Personalities in One Service:**
- **Hello**: Your friendly neighborhood greeter with CloudEvent superpowers
- **Talk**: A streaming ELIZA therapist bot (because who doesn't need therapy while debugging?)
- **Background**: A process simulator that pretends to spin up services across different protocols

🔒 **Security First**: Local TLS certificates with `mkcert` (because even localhost deserves encryption)

⚡ **Modern Stack**: ConnectRPC + Fastify + TypeScript + Buf CLI (the cool kids' table)

🌊 **Streaming Ready**: Both client and server streaming, because sometimes one message just isn't enough

## 🛠️ Prerequisites

Before we dive into this TypeScript wonderland, make sure you have:

- **Node.js** (because obviously)
- **npm** (comes free with Node.js, like ketchup with fries)
- **[Buf CLI](https://buf.build)** (the protobuf Swiss Army knife)
- **mkcert** (for those sweet, sweet local certificates)
- **grpcurl** *(optional, but highly recommended for showing off)*

### Quick Setup for the Impatient

```bash
# Install buf (if you haven't already)
npm install -g @bufbuild/buf

# Install mkcert (macOS)
brew install mkcert

# Install mkcert (Linux)
curl -JLO "https://dl.filippo.io/mkcert/latest?for=linux/amd64"
chmod +x mkcert-v*-linux-amd64
sudo mv mkcert-v*-linux-amd64 /usr/local/bin/mkcert
```

## 🚀 Getting Started

### 1. Clone & Install
```bash
git clone
cd basic-grpc-service-node
npm install
```

### 2. Generate Your Certificates (Trust Issues Much?)
```bash
npm run cert:generate
```
*This creates local certificates that your browser will actually trust. Magic!*

### 3. Generate Proto Code (Optional, but Fun)
```bash
npm run buf:generate
```
*Watch as Buf transforms your `.proto` files into beautiful TypeScript. It's like a protobuf makeover show!*

### 4. Start the Show
```bash
npm start
```

🎉 **Boom!** Your gRPC service is now running on `https://127.0.0.1:8443` with all the bells, whistles, and TLS goodness.

## 🎪 Meet Your Service Methods

### 👋 `Hello` - The Friendly Greeter
**What it does:** Takes your message and wraps it in a CloudEvent like a present

```bash
# Using buf curl (the modern way)
buf curl --schema ./proto -d '{"message": "Universe"}' \
https://127.0.0.1:8443/basic.v1.BasicService/Hello

# Using grpcurl (the classic way)
grpcurl 127.0.0.1:8443 basic.v1.BasicService/Hello -d '{"message": "Universe"}'
```

**Response:** A CloudEvent containing a greeting that would make your grandmother proud.

### 💬 `Talk` - Your Personal Streaming Therapist
**What it does:** Engages you in meaningful conversation using ELIZA-style responses. It's like having a therapist, but one that runs on your localhost.

```bash
# Stream some deep thoughts
cat <