ob-grpc provides functions for making grpc calls through org-babel, using grpcurl.
Not available on melpa yet. Currently the easiest way to install is to use straight.el
(straight-use-package
'(ob-grpc :type git :host github :repo "shsms/ob-grpc"))
Or with use-package
+ straight.el
(use-package ob-grpc
:straight (ob-grpc :type git :host github :repo "shsms/ob-grpc")
:bind (:map org-mode-map
("C-c g i" . ob-grpc-init)
("C-c g b" . ob-grpc-insert-block)))
Also install grpcurl.
Optionally, add the below to your init.el
to prevent a confirmation request from
org-babel every time you execute a block:
(defun my-org-confirm-babel-evaluate (lang body)
(not (member lang '(
"grpc"
;; other source languages
))))
(setq org-confirm-babel-evaluate 'my-org-confirm-babel-evaluate)
In an empty org buffer, run M-x ob-grpc-init
. This would add these
properties to the buffer:
:PROPERTIES:
:GRPC-ENDPOINT: [::1]:8080
:PROTO-FILE: ./proto/service.proto
:PROTO-IMPORT-PATH: proto
:PLAIN-TEXT: yes
:GRPC-BLOCK-PREFIX: * TODO ${method}\n\n# ${decl}\n
:END:
Notes:
- Update their values as necessary.
- When using TLS, set
:PLAIN-TEXT:
tono
. - Separate multiple import paths by a space character.
- The
:GRPC-BLOCK-PREFIX:
is a template for a prefix to the org-babel block. Check below for details on how to configure.
Run M-x ob-grpc-insert-block
. That would prompt for a method name,
with all the methods in the :PROTO-FILE:
as completion options.
Choose one, and it will automatically insert an org block, with the
method name, and a template message for the request type of the
message. For example,
> #+begin_src grpc :method echo.Echo.Echo
> {
> "str": ""
> }
> #+end_src
Update the request object as necessary, and press C-c C-c
inside the block.
If you don’t want any text to be added in front of each of your
org-babel blocks, this can be set to :GRPC-BLOCK-PREFIX: nil
. The
default value :GRPC-BLOCK-PREFIX: * TODO ${method}\n\n# ${decl}\n
adds
a new TODO org-section, followed by a comment with the grpc declation
of the selected method. Here’s a list of template arguments that can
be used here:
${method}
- the name of the method, without the name of the service.
${method-full}
- the name of the method including the service name.
${decl}
- the entire declaration of the grpc method, including the name, request and return types.
${req-type}
- the name of the request type.
${resp-type}
- the name of the response type.
There is not a lot of error handling at the moment. So when something
doesn’t work as expected, visit the *Messages*
buffer. All the calls
to grpcurl
and responses are logged there.
No support for streaming grpc methods yet.