pets/

directory
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 25, 2023 License: Apache-2.0

README

Pet Store

This is an example app that makes use of all of the protocol translation features of Vanguard.

It is built on top of the PetStore API that is available as an OpenAPI spec. This example includes a Protobuf definition that matches the "pets" entry points of the PetStore. (The "store" and "users" entry points are not included.)

This example includes two components:

  1. pets-fe: The Pets Frontend is a server that accepts requests in any a variety of protocols: REST, Connect, gRPC, or gRPC-Web. It uses the Vanguard middleware to wrap a reverse proxy, so it translates the requests to an RPC protocol and then forwards them to the pets-be backend service.

    This server listens on three ports:

    • 30301: Requests to this port will be translated to the Connect protocol before being sent to the backend.
    • 30302: Requests to this port will be translated to the gRPC protocol before being sent to the backend. It will also transcode requests that use the JSON format to the Protobuf binary format.
    • 30303: Requests to this port will be translated to the gRPC-Web protocol before being sent to the backend. It will also transcode requests that use the JSON format to the Protobuf binary format.

    This server traces incoming requests to stdout.

  2. pets-be: The Pets Backend is an RPC server that accepts RPC requests from the frontend. It also uses the Vanguard middleware to wrap a reverse proxy, so it translates RPC requests into REST requests that are forwarded to the public example API server at petstore.swagger.io.

    This server listens for requests on port 30304.

    This server traces both incoming (RPC) and outgoing (REST) requests.

You can try out these servers by running both and then issuing the following curl command:

curl 'http://localhost:30303/pet/findByStatus?status=available' -v -X GET

The above sends a simple REST request to the frontend. This will get translated to gRPC-Web and sent to the backend. The backend will then turn it back into a REST request and send to petstore.swagger.io. And all of this activity can be seen in the log output from the servers.

Directories

Path Synopsis
cmd
gen/io/swagger/petstore/v2/petstorev2connect
The service defined herein comes from v2 of the Petstore service, which is used as an example for Swagger/OpenAPI.
The service defined herein comes from v2 of the Petstore service, which is used as an example for Swagger/OpenAPI.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL