Giter VIP home page Giter VIP logo

examples-go's Introduction

examples-go

Build

examples-go contains an example RPC service built with Connect. Its API is defined by a Protocol Buffer schema, and the service supports the gRPC, gRPC-Web, and Connect protocols.

The service emulates the DOCTOR script written for Joseph Weizenbaum's 1966 ELIZA natural language processing system. It responds to your statements as a stereotypical psychotherapist might; since the original program was a demonstration of the superficiality of human-computer communication, the therapy is not very convincing.

For more on Connect, see the announcement blog post, the documentation on connectrpc.com, or the Connect repo.

Example

The service is running on https://demo.connectrpc.com. To make an RPC with cURL, using the Connect protocol:

curl --header "Content-Type: application/json" \
    --data '{"sentence": "I feel happy."}' \
    https://demo.connectrpc.com/connectrpc.eliza.v1.ElizaService/Say

To make the same RPC, but using grpcurl and the gRPC protocol:

grpcurl \
    -d '{"sentence": "I feel happy."}' \
    demo.connectrpc.com:443 \
    connectrpc.eliza.v1.ElizaService/Say

Legal

Offered under the Apache 2 license.

examples-go's People

Contributors

akshayjshah avatar chrispine avatar dependabot[bot] avatar drice-buf avatar smallsamantha avatar srikrsna-buf avatar timostamm avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

examples-go's Issues

question: how-to consume the Eliza service using http/2

Hi buf team, and thank you for the awesome work you're doing on buf cli.

While the docs explain how to consume this RPC service using http/1 and grpc,
there is no example for http/2.
Would you be so kind to explain what is going wrong on the below attempt:

Based on the specification https://github.com/grpc/grpc/blob/master/doc/PROTOCOL-HTTP2.md of what is going through the wire. The following "should" work:

  1. I should encode the message in protobuf format, I chose python in this case
import eliza_pb2
import google.protobuf.json_format

message = {"sentence": "I feel happy."}
message_data = google.protobuf.json_format.ParseDict(message, eliza_pb2.SayRequest())
message_data = message_data.SerializeToString()
  1. And construct the grpc frame
message_length = "{:08x}".format(len(message_data)).encode("utf-8")
compressed_flag = "{:02x}".format(0).encode("utf-8")

So, the grpc frame must be compressed_flag + message_length + binascii.hexlify(message_data) and results in:

  • in hex format 000000000f0a0d49206665656c2068617070792e
  • or, in ascii format \x00\x00\x00\x00\x0f\n\rI feel happy.
  1. Let's issue the request to the gRPC service and using curl
echo -en '000000000f0a0d49206665656c2068617070792e' | curl --verbose --http2 --header "Content-Type: application/grpc+proto" --header "TE: trailers" --data-binary @- --output -  https://demo.connect.build/buf.connect.demo.eliza.v1.ElizaService/Say
*   Trying 35.227.208.237:443...
* Connected to demo.connect.build (35.227.208.237) port 443 (#0)
* ALPN: offers h2
* ALPN: offers http/1.1
*  CAfile: /etc/ssl/cert.pem
*  CApath: none
* (304) (OUT), TLS handshake, Client hello (1):
* (304) (IN), TLS handshake, Server hello (2):
* (304) (IN), TLS handshake, Unknown (8):
* (304) (IN), TLS handshake, Certificate (11):
* (304) (IN), TLS handshake, CERT verify (15):
* (304) (IN), TLS handshake, Finished (20):
* (304) (OUT), TLS handshake, Finished (20):
* SSL connection using TLSv1.3 / AEAD-AES256-GCM-SHA384
* ALPN: server accepted h2
* Server certificate:
*  subject: CN=demo.connect.build
*  start date: Apr 24 09:24:05 2023 GMT
*  expire date: Jul 23 10:17:38 2023 GMT
*  subjectAltName: host "demo.connect.build" matched cert's "demo.connect.build"
*  issuer: C=US; O=Google Trust Services LLC; CN=GTS CA 1D4
*  SSL certificate verify ok.
* Using HTTP2, server supports multiplexing
* Copying HTTP/2 data in stream buffer to connection buffer after upgrade: len=0
* h2h3 [:method: POST]
* h2h3 [:path: /buf.connect.demo.eliza.v1.ElizaService/Say]
* h2h3 [:scheme: https]
* h2h3 [:authority: demo.connect.build]
* h2h3 [user-agent: curl/7.86.0]
* h2h3 [accept: */*]
* h2h3 [content-type: application/grpc]
* h2h3 [te: trailers]
* h2h3 [content-length: 40]
* Using Stream ID: 1 (easy handle 0x7fe95980fc00)
> POST /buf.connect.demo.eliza.v1.ElizaService/Say HTTP/2
> Host: demo.connect.build
> user-agent: curl/7.86.0
> accept: */*
> content-type: application/grpc
> te: trailers
> content-length: 40
> 
* We are completely uploaded and fine
< HTTP/2 200 
< content-type: application/grpc
< grpc-accept-encoding: gzip
< trailer: Grpc-Status
< trailer: Grpc-Message
< trailer: Grpc-Status-Details-Bin
< vary: Origin
< date: Sat, 06 May 2023 17:49:38 GMT
< server: Google Frontend
< traceparent: 00-dffacc1975cead20ae1edd176a849847-b5a4abbeec7bef40-01
< x-cloud-trace-context: dffacc1975cead20ae1edd176a849847/13088775253545185088;o=1
< via: 1.1 google
< content-length: 0
< alt-svc: h3=":443"; ma=2592000,h3-29=":443"; ma=2592000
< 
< grpc-message: protocol error: promised 808464432 bytes in enveloped message, got 35 bytes
< grpc-status: 3
< grpc-status-details-bin: CAMSS3Byb3RvY29sIGVycm9yOiBwcm9taXNlZCA4MDg0NjQ0MzIgYnl0ZXMgaW4gZW52ZWxvcGVkIG1lc3NhZ2UsIGdvdCAzNSBieXRlcw
* Connection #0 to host demo.connect.build left intact

The grpc service accepts the request in question < HTTP/2 200 but complains about

< grpc-message: protocol error: promised 808464432 bytes in enveloped message, got 35 bytes
< grpc-status: 3
< grpc-status-details-bin: CAMSS3Byb3RvY29sIGVycm9yOiBwcm9taXNlZCA4MDg0NjQ0MzIgYnl0ZXMgaW4gZW52ZWxvcGVkIG1lc3NhZ2UsIGdvdCAzNSBieXRlcw

Can you please advise why is this happening?

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.