Categorygithub.com/kogxi/stub-server
repository
0.1.4
Repository: https://github.com/kogxi/stub-server.git
Documentation: pkg.go.dev

# Packages

No description provided by the author

# README

PoC Stub Server

The Stub Server is a proof of concept of a HTTP(s) and gRPC stub server. No need to invoke the proto compiler - the proto files are loaded dynamically. The HTTP and gRPC server run on the same port.

Usage

Installation

go install github.com/kogxi/stub-server/cmd

Parameters

NameUsageRequiredDefault 
addressAddress to listen onfalse:58001
certPath to the cert filefalse-
keyPath to the key filefalse-
protoDirectory containing the .proto filesfalse-
stubsDirectory containing the .json gRPC stub filestrue-
httpDirectory containing the .json HTTP stub filestrue-

HTTP stub server

The HTTP(s) stub requires only the path fields. By default the stub server returns the HTTP status code 200 (OK).

Minimal example

{
    "path": "/helloworld"
}

Fully specified example

{
    "path": "/helloworld",
    "method": "GET",
    "response": {
        "header": {
          "Content-Type":  ["application/json"]
        },
        "body": {"message": "Hello from http stub"},
        "status": 201
    }
}

To start the HTTP stub server one needs to specify the path to the HTTP stub dir. ./stub-server --http "./examples/httpstubs"

gRPC stub server

The gRPC stub requires the service, method and outputs fields.

Success example

{
    "service": "helloworld.Greeter",
    "method": "SayHello",
    "output": {
        "data": {
            "message": "Hello from proto stub"
        }
    }
}

Error example

{
    "service": "helloworld.Greeter",
    "method": "SayHello",
    "output": {
        "error": {
            "code": 3,
            "message": "Invalid request"
        }
    }
}

To start the gRPC stub server one needs to specify the path to the gRPC stub directory and the path to the proto files. E.g., ./stub-server --proto "./examples/protos" --stubs "./examples/protostubs"