Tuesday, May 18, 2021

Twirp At 99

Here are some brief reflections on the RPC and Twirp workshop I completed yesterday.

  • chi HTTP framework listening on port 3000 in main.go
  • Twirp server is attached to POST requests with wildcard path prefix
  • Define proto file, kind of like a schema, define the shape of what parameters a request and response will have
  • Can run twirpgen command
99dev twirp init <service>

to scaffold folder structure and basic proto file

  • Go server code needs to align to what we defined in the RPC, Server struct has some instance methods that are like controller endpoints, access to request parameters and send back response struct to client
  • Can make curl requests to those endpoints
  • When you change proto file you also need to regenerate RPCs with Twirp, command is
99dev twirp generate <service>
  • You basically then have access to clients for Go, PHP and Ruby
  • PHP generated a bunch of classes that you could interface with directly, I imagine ruby is very similar