- Click on the "Open in Dev Containers" badge above to open the project in a Dev Container. If this does not work, clone the repository by following your usual git workflow, then open it in VS Code.
- Optional: Copy
.env.template
to.env
and add your OpenAI API key. - Rebuid the container by running the
Remote-Containers: Rebuild Container
command. - Open a terminal in VS Code and run the following command:
go run main.go
- Open a new terminal and run the following command:
grpcurl -plaintext -d '{"drink_name_request": {"name": "Pan Galactic Gargle Blaster"}}' localhost:50051 bar.Bar/GetDrink | sed 's/%3A/:/g; s/%2F/\//g; s/%3D/=/g; s/%3F/?/g; s/%26/\&/g' | jq
- You should see a JSON response with the drink details.
- Edit
bar.yaml
. - Run the following command to generate the a protobuf binary:
gnostic --pb-out=. bar.yaml
- Run the following command to generate the gRPC protobuf file with annotations:
gnostic-grpc -input bar.pb -output .
- Run the following command to generate the gRPC and gRPC-Gateway code:
buf generate
- Run the following command to generate the SDKs:
speakeasy generate sdk \
--schema bar.yaml \
--lang typescript \
--out ./bar-sdk-typescript
-
Rebuild the container by running the
Remote-Containers: Rebuild Container
command. -
Continue from step 4 in the Getting Started section.
We can test the gRPC and gRPC-Gateway services using grpcurl
and curl
.
Run the following commands to test the gRPC service:
# Create a drink
grpcurl -plaintext -d '{"ingredients_request": {"ingredients": ["Gin", "Tonic water", "Lime juice"]}}' localhost:50051 bar.Bar/CreateDrink
# Get the drink
grpcurl -plaintext -d '{"drink_name_request": {"name": "Pan Galactic Gargle Blaster"}}' localhost:50051 bar.Bar/GetDrink
Run the following commands to test the gRPC-Gateway service:
# Create a drink
curl -X POST -H "Content-Type: application/json" -d '{"ingredients": ["Gin", "Tonic water", "Lime juice"]}' http://localhost:8080/create-drink
# Get the drink
curl -X POST -H "Content-Type: application/json" -d '{"name": "Pan Galactic Gargle Blaster"}' http://localhost:8080/get-drink
This project is licensed under the MIT License - see the LICENSE file for details.