skir_client/service_client
Types
Error returned by invoke_remote when the server responds with a non-2xx status code or when a network-level failure occurs.
pub type RpcError {
RpcError(status_code: Int, message: String)
}
Constructors
-
RpcError(status_code: Int, message: String)Arguments
- status_code
-
HTTP status code from the server, or 0 for network-level failures.
0usually means the request could not be completed (DNS, refused connection, timeout, etc.), rather than an application error response. - message
-
Human-readable description of the error.
Sends RPCs to a SkirRPC service.
The send_fn parameter accepts an HTTP request and returns a response. Its signature matches httpc.send from the gleam_httpc package, so you can pass httpc.send directly (or any compatible function).
This client is usually used by generated helper functions, but it is also safe to use directly.
Example: import gleam/httpc import skir_client/service_client let assert Ok(client) = service_client.new(“http://localhost:8787/myapi”, httpc.send)
A common pattern is to create the client once at startup and reuse it.
pub opaque type ServiceClient(send_err)
Values
pub fn invoke_remote(
client: ServiceClient(send_err),
method: method.Method(req, resp),
request_value: req,
) -> Result(resp, RpcError)
Invokes method on the remote service with the given request_value.
This function returns:
Ok(response)when the remote method succeeds.Error(RpcError(...))for transport failures, non-2xx responses, or response-decoding failures.
Example: let result = service_client.invoke_remote( client, user_out.get_user_method(), request, )
pub fn new(
service_url: String,
send_fn: fn(request.Request(String)) -> Result(
response.Response(String),
send_err,
),
) -> Result(ServiceClient(send_err), String)
Creates a ServiceClient pointing at service_url.
send_fn is the HTTP send function. Pass httpc.send from gleam_httpc or any function with the same signature.
Returns an error string if service_url contains a query string or is not a valid URL.
Tip: pass the base endpoint URL (for example
"http://localhost:8787/myapi") without query parameters.
pub fn with_default_header(
client: ServiceClient(send_err),
key: String,
value: String,
) -> ServiceClient(send_err)
Adds an HTTP header sent with every invocation.
May be chained: client |> with_default_header(“Authorization”, “Bearer …”)