GithubHelp home page GithubHelp logo

protoc-gen-connect-mock-server's Introduction

protoc-gen-connect-mock-server

Generate a functional mock server from a protobuf specification.

Usage

Make sure the protoc-gen-connect-mock-server binary is compiled and in your $PATH.

Add it as a plugin to your buf.gen.yaml file along with buf.build/protocolbuffers/go and buf.build/bufbuild/connect-go:

version: v1
managed:
  enabled: true
  go_package_prefix:
    default: <your Go module>/gen
plugins:
  - plugin: buf.build/protocolbuffers/go
    out: gen
    opt: paths=source_relative
  - plugin: buf.build/bufbuild/connect-go
    out: gen
    opt: paths=source_relative
  - plugin: connect-mock-server
    out: gen
    opt: paths=source_relative

Create a protobuf service at eliza/v1/eliza.proto like this:

syntax = "proto3";

package eliza.v1;

message SayRequest {
  string sentence = 1;
}

message SayResponse {
  string sentence = 1;
}

service ElizaService {
  rpc Say(SayRequest) returns (SayResponse) {}
}

Generate the build:

buf generate

Install dependencies

go mod tidy

Run the mock server

go run gen/eliza/v1/elizaconnectmockserver/main.pb.go

Test the service:

buf curl --schema eliza/v1/eliza.proto --data '{"sentence": "hello"}' http://localhost:8080/eliza.v1.ElizaService/Say

You should get a response like this:

{
  "sentence": "string"
}

Run it in dynamic mode with the -d flag

go run gen/eliza/v1/elizaconnectmockserver/main.pb.go -d

Running the same buf curl command above should return a different result each time like this:

{
  "sentence": "QDcyVRjMUAhhPMpSPwSXxxgMx"
}

Status: Very Unstable

Pretty much everything in flight. The code is a mess. APIs can change anytime.

protoc-gen-connect-mock-server's People

Contributors

jasonblanchard avatar

Watchers

James Cloos avatar  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.