A proxy server than converts JSON request bodies to protocol buffers

Welcome to Protoxy 👋

codecov Go Report Card License: MIT

What is Protoxy?

Protoxy allows you to test your REST APIs that use Protocol Buffer serialization through Postman and other API testing tools which do not natively support Protobuf encoding. Protoxy is a proxy server that converts the JSON in your request body to the appropriate Protobuf message type and transforms the response from your back-end back into JSON. You don't need to make any changes to your source code to use Protoxy.

Install

go get github.com/camgraff/protoxy

Usage

Consider a proto file located at ./protos/example.proto that looks like this:

syntax = "proto3";
package example;

message ExampleRequest {
    string text = 1;
    int32 number = 2;
    repeated string list = 3;
}

message ExampleResponse {
    string text = 1;
}

  1. Start the server by specifying your import paths, proto file names, and optional port.

    protoxy -I ./protos/ --port 7777 example.proto
    
  2. Configure Postman to send requests through the Proxy server. Postman proxy config

  3. Add your fully-qualified message names as params in the Content-Type header.

    Content-Type: application/x-protobuf; reqMsg="example.ExampleRequest"; respMsg="example.ExampleResponse";
    
  4. Send your request as a raw JSON body.

    {
      "text": "some text",
      "number": 123,
      "list": ["this", "is", "a", "list"]
    }
    

    The response is:

    {
      "text": "this response was automagically converted to JSON"
    }
    

Using Protobuf in Query String

Protoxy also supports sending protobuf messages as a base64 encoded query string in the URL. To do this, add an additional param qs in the header whose value corresponds to the query string parameter. For example:

Content-Type: application/x-protobuf; reqMsg="example.ExampleRequest"; respMsg="example.ExampleResponse"; qs="proto_body";

This will result in a URL like:

http://example.com?proto_body={base64 encoding of example.ExampleRequest}

Handling Multiple Response Message Types

If your API sends multiple response message types, the respMsg parameter accepts a comma-seperated list of values.

Content-Type: application/x-protobuf; reqMsg="example.ExampleRequest"; respMsg="example.ExampleResponse,example.DifferentResponse";

Note: Protoxy will attempt to unmarshal your proto messages into each type of response and will send the first successful one. This can produce unexpected results because the same wire-format message can successfully be unmarshalled into multiple proto message types depending on the fields in the proto message. If possible, it is best to ensure that you back-end server returns only one response type per route.

Author

👤 Cam Graff

🤝 Contributing

Contributions, issues and feature requests are welcome!

Feel free to check issues page.

Show your support

Give a ⭐️ if this project helped you!


Similar Resources

A simple SHOUTcast server.

DudelDu DudelDu is a simple audio/video streaming server using the SHOUTcast protocol. Features Supports various streaming clients: VLC, ServeStream,

Nov 20, 2022

A feature flag solution, with only a YAML file in the backend (S3, GitHub, HTTP, local file ...), no server to install, just add a file in a central system and refer to it. 🎛️

A feature flag solution, with only a YAML file in the backend (S3, GitHub, HTTP, local file ...), no server to install, just add a file in a central system and refer to it. 🎛️

🎛️ go-feature-flag A feature flag solution, with YAML file in the backend (S3, GitHub, HTTP, local file ...). No server to install, just add a file i

Dec 29, 2022

An XMPP server written in Go (Golang).

jackal An XMPP server written in Go. About jackal is a free, open-source, high performance XMPP server which aims to be known for its stability, simpl

Dec 29, 2022

High-performance PHP application server, load-balancer and process manager written in Golang

High-performance PHP application server, load-balancer and process manager written in Golang

[RR2-BETA] RoadRunner is an open-source (MIT licensed) high-performance PHP application server, load balancer, and process manager. It supports runnin

Jan 4, 2023

Fully featured and highly configurable SFTP server with optional FTP/S and WebDAV support - S3, Google Cloud Storage, Azure Blob

SFTPGo Fully featured and highly configurable SFTP server with optional FTP/S and WebDAV support, written in Go. Several storage backends are supporte

Jan 9, 2023

A RTP - WebRTC broadcast server for Project Lightspeed.

Project Lightspeed WebRTC A RTP - WebRTC server based on Pion written in Go. This server accepts RTP packets on port 65535 and broadcasts them via We

Sep 1, 2022

Heart 💜A high performance Lua web server with a simple, powerful API

Heart 💜A high performance Lua web server with a simple, powerful API

Heart 💜 A high performance Lua web server with a simple, powerful API. See the full documentation here. Overview Heart combines Go's fasthttp with Lu

Aug 31, 2022

The Galène videoconferencing server

The Galène videoconferencing server

Dec 28, 2022

A push notification server written in Go (Golang).

A push notification server written in Go (Golang).

A push notification micro server using Gin framework written in Go (Golang)

Jan 9, 2023
ready-to-use RTSP / RTMP server and proxy that allows to read, publish and proxy video and audio streams
ready-to-use RTSP / RTMP server and proxy that allows to read, publish and proxy video and audio streams

rtsp-simple-server is a simple, ready-to-use and zero-dependency RTSP / RTMP server and proxy, a software that allows users to publish, read and proxy live video and audio streams. RTSP is a specification that describes how to perform these operations with the help of a server, that is contacted by both publishers and readers and relays the publisher's streams to the readers.

Dec 31, 2022
A Language Server Protocol (LSP) server for Jsonnet

Jsonnet Language Server A Language Server Protocol (LSP) server for Jsonnet. Features Jump to definition self-support.mp4 dollar-support.mp4 Error/War

Dec 14, 2022
⚡ A fast, lightweight, and secure chat protocol, client and server, written in Go.

⚡ A fast, lightweight, and secure chat protocol, client and server, written in Go.

Oct 27, 2022
Tiny Go webserver that prints os information and HTTP request to output

whoami Tiny Go webserver that prints os information and HTTP request to output Usage Paths /data?size=n[&unit=u]: creates a response with a size n. Th

Nov 2, 2021
a simple http server as replacement of python -m http.server

ser a simple http server as replacement of python -m http.server

Dec 5, 2022
OpenAPI specs for your Go server, generated at server runtime. No CLI, no code generation, and no HTTP

Overview "oas" is short for "OpenAPI Spec". Go package for generating OpenAPI docs at runtime. Non-features: No code generation. No CLI. No magic comm

Dec 3, 2021
Reverse proxy with automatically obtains TLS certificates from Let's Encrypt

Русскоязычное описание ниже (Russian below). English description Home page: https://github.com/rekby/lets-proxy2 Features: http-01 and tls-alpn-01 val

Dec 11, 2022
:tophat: Small self-contained pure-Go web server with Lua, Markdown, HTTP/2, QUIC, Redis and PostgreSQL support
:tophat: Small self-contained pure-Go web server with Lua, Markdown, HTTP/2, QUIC, Redis and PostgreSQL support

Web server with built-in support for QUIC, HTTP/2, Lua, Markdown, Pongo2, HyperApp, Amber, Sass(SCSS), GCSS, JSX, BoltDB (built-in, stores the databas

Jan 1, 2023
Fast, multi-platform web server with automatic HTTPS
Fast, multi-platform web server with automatic HTTPS

a project Every site on HTTPS Caddy is an extensible server platform that uses TLS by default. Releases · Documentation · Get Help Menu Features Insta

Jan 1, 2023