Example Projects
Bufrnix includes several example projects that demonstrate how to use Protocol Buffers with different languages and frameworks. These examples are complete, working projects that you can use as starting points for your own applications.
Simple Go gRPC Example
Section titled “Simple Go gRPC Example”A basic example demonstrating Go gRPC server and client communication.
Features
Section titled “Features”- Simple gRPC server and client implementation
- User service with create and get operations
- In-memory storage for demonstration purposes
- Error handling and validation
Source Code
Section titled “Source Code”Check out the simple-flake example on GitHub.
Running the Example
Section titled “Running the Example”# Navigate to the example directorycd examples/simple-flake
# Generate the proto codenix run .#packages.x86_64-linux.bufrnix generate
# Run the examplego run main.go
JavaScript/TypeScript Example
Section titled “JavaScript/TypeScript Example”Demonstrates using Protocol Buffers with Node.js and TypeScript.
Features
Section titled “Features”- TypeScript support with type definitions
- Modern ES modules
- Simple client implementation
- Integration with npm packages
Source Code
Section titled “Source Code”Check out the js-example on GitHub.
Running the Example
Section titled “Running the Example”# Navigate to the example directorycd examples/js-example
# Generate the proto codenix develop -c bufrnix generate
# Install dependenciesnpm install
# Run the examplenpm start
Dart Example
Section titled “Dart Example”Shows how to use Protocol Buffers with Dart and gRPC for Flutter or server applications.
Features
Section titled “Features”- Dart class generation for Protocol Buffers
- gRPC client implementation
- Compatible with Flutter applications
- Demo of async/await usage with gRPC
Source Code
Section titled “Source Code”Check out the dart-example on GitHub.
Running the Example
Section titled “Running the Example”# Navigate to the example directorycd examples/dart-example
# Generate the proto codenix develop -c bufrnix generate
# Run the exampledart lib/main.dart
PHP Twirp Example
Section titled “PHP Twirp Example”Demonstrates using Protocol Buffers with PHP and the Twirp RPC framework.
Features
Section titled “Features”- PHP class generation for Protocol Buffers
- Twirp HTTP server and client
- Composer integration
- Simple API implementation
Source Code
Section titled “Source Code”Check out the php-twirp example on GitHub.
Running the Example
Section titled “Running the Example”# Navigate to the example directorycd examples/php-twirp
# Generate the proto codenix develop -c bufrnix generate
# Install dependenciescomposer install
# Run the example (implementation may vary)php -S localhost:8080 -t public
Creating Your Own Example
Section titled “Creating Your Own Example”To create your own example:
- Set up a new directory with a
flake.nix
file - Add Bufrnix as an input
- Configure Bufrnix for your target languages
- Create your
.proto
files in the appropriate directory - Run
nix develop -c bufrnix generate
to generate code - Implement your application using the generated code
You can use any of the existing examples as a starting point for your own project.
C# Basic Example
Section titled “C# Basic Example”Demonstrates basic Protocol Buffers usage with C# and .NET.
Features
Section titled “Features”- C# class generation for Protocol Buffers
- Binary and JSON serialization
- Nested messages and enums
- Generated .csproj file for easy integration
Source Code
Section titled “Source Code”Check out the csharp-basic on GitHub.
Running the Example
Section titled “Running the Example”# Navigate to the example directorycd examples/csharp-basic
# Generate the proto codenix build .#proto./result/bin/bufrnix
# Build and run the examplenix run
C# gRPC Example
Section titled “C# gRPC Example”Shows how to build gRPC services with C# and ASP.NET Core.
Features
Section titled “Features”- gRPC service implementation with ASP.NET Core
- Client console application
- Unary and streaming RPC examples
- Modern .NET 8.0 integration
Source Code
Section titled “Source Code”Check out the csharp-grpc on GitHub.
Running the Example
Section titled “Running the Example”# Navigate to the example directorycd examples/csharp-grpc
# Generate the proto codenix build .#proto./result/bin/bufrnix
# Run the server (in one terminal)nix run .#server
# Run the client (in another terminal)nix run .#client
C# Flake-parts Example
Section titled “C# Flake-parts Example”Demonstrates using flake-parts with Bufrnix for C# projects.
Features
Section titled “Features”- Uses
flake-parts
for modular flake configuration - Generates a .NET project with Protocol Buffers
Source Code
Section titled “Source Code”Check out the csharp-flake-parts on GitHub.
Running the Example
Section titled “Running the Example”# Navigate to the example directorycd examples/csharp-flake-parts
# Generate the proto codenix build .#proto
# Build and run the examplenix run .#app
Kotlin Basic Example
Section titled “Kotlin Basic Example”Demonstrates basic Protocol Buffers usage with Kotlin.
Features
Section titled “Features”- Kotlin DSL builders for message creation
- Immutable message updates with
copy
- Type-safe builders and null safety
- Generated Gradle build file
Source Code
Section titled “Source Code”Check out the kotlin-basic on GitHub.
Running the Example
Section titled “Running the Example”# Navigate to the example directorycd examples/kotlin-basic
# Generate the proto codenix build .#proto./result/bin/bufrnix
# Build and run with Gradlecd gen/kotlingradle run
Kotlin gRPC Example
Section titled “Kotlin gRPC Example”Shows how to build gRPC services with Kotlin coroutines.
Features
Section titled “Features”- Coroutine-based gRPC services
- Flow-based streaming APIs
- Unary and streaming RPC examples
- Modern Kotlin idioms
Source Code
Section titled “Source Code”Check out the kotlin-grpc on GitHub.
Running the Example
Section titled “Running the Example”# Navigate to the example directorycd examples/kotlin-grpc
# Generate the proto codenix build .#proto./result/bin/bufrnix
# Run the server (in one terminal)cd gen/kotlin && gradle runServer
# Run the client (in another terminal)cd gen/kotlin && gradle runClient
Swift Example
Section titled “Swift Example”Demonstrates using Protocol Buffers with Swift for iOS, macOS, and server applications.
Features
Section titled “Features”- Swift struct generation with Codable support
- Type-safe Protocol Buffer messages
- SwiftProtobuf integration
- Compatible with SwiftPM and Xcode projects
Source Code
Section titled “Source Code”Check out the swift-example on GitHub.
Running the Example
Section titled “Running the Example”# Navigate to the example directorycd examples/swift-example
# Generate the proto codenix develop -c bufrnix_init && bufrnix
# Build and run the exampleswift buildswift run
Additional Resources
Section titled “Additional Resources”- Simple-flake README - More details on the Go example
- JS Example README - JavaScript integration details
- Dart Example README - Dart and Flutter integration
- PHP Twirp README - PHP and Twirp integration
- C# Basic README - C# and .NET integration
- C# gRPC README - C# gRPC with ASP.NET Core
- C# Flake-parts README - Using flake-parts with C#
- Kotlin Basic README - Kotlin with DSL builders
- Kotlin gRPC README - Kotlin gRPC with coroutines
- Swift Example README - Swift and SwiftProtobuf integration