Elm call rpc

From JonLatane/jonline · View interactive version

Elm call rpc is an AI agent skill from the GitHub repository JonLatane/jonline. Call a Rellm gRPC RPC (from protos/*.proto) from Elm SPA code (frontends/elm-spa). Use when writing or wiring up a new fetch/mutation against the backend from a page or Shared panel.

How to use this skill

Skill file

Basic shape

Each RPC (protos/rellm.proto's service Rellm) has a generated Grpc.Rpc req res value in Proto.Rellm.Rellm (e.g. Rellm.updatePost, Rellm.createPost, Rellm.getPosts), from the anmolitor/elm-grpc package (Grpc module).

Grpc.new Rellm.updatePost requestValue
    |> Grpc.setHost (AccountsPanel.serverUrl server)
    |> Grpc.addHeader "authorization" token   - only for authenticated calls
    |> Grpc.toTask                            - : Task Grpc.Error res

Use Grpc.toTask when chaining (Task.andThen) or Task.attempting yourself; Grpc.toCmd if you just want a Cmd msg directly.

Many RPCs (CreatePost, UpdatePost, ...) take/return the whole resource message directly (Post -> Post), not a separate FooRequest/FooResponse pair — check the actual rpc line in the .proto file rather than assuming a request wrapper exists.

Auth / token refresh: use `Shared.MaybeAccountRequest`

Don't call Grpc.addHeader "authorization" with a token you're holding onto — it may have expired. Instead:

Read-modify-write safety

Some RPCs take and unconditionally apply a whole record server-side — e.g. UpdatePost (backend/src/rpcs/posts/update_post.rs) overwrites visibility/media/shareable/etc. from whatever Post you send, not just the field you intended to change. If you're changing one field of something fetched a while ago (user was editing in a text box, a panel sat open, etc.), re-fetch it fresh immediately before submitting and overlay only your change onto that fresh copy — don't resubmit a possibly-stale in-hand snapshot. See Shared/MarkdownPanel.elm's saveTask (Task.andThens a fresh GetPosts into the eventual UpdatePost) for the pattern. Check the corresponding backend/src/rpcs/**/*.rs handler when in doubt about which fields get blindly overwritten vs. merged.

Errors

AccountsPanel.grpcErrorToString : Grpc.Error -> String is the shared formatter (Grpc.BadUrl/Timeout/NetworkError/BadStatus { errMessage }/BadBody) used for displaying RPC failures — use it instead of writing a new Grpc.Error -> String case expression.

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.