App Access Flow
App Access Flow
This page describes the complete access path of a micro-app that has a backend service: from the frontend to the Go service and back.
Remember this first
The frontend only calls $gm.request() and never connects to the Unix Socket directly. /api/call/{org}/{app}/{method} is the unified entry point provided by the desktop platform, and the Go backend only has to listen on the Socket and register RPC methods.
Overview
Once the debug app is created and the backend service is running, the GM Desktop platform performs health checks automatically: every 5 seconds the platform calls the ping method registered by the backend, and treats the service as alive when it receives pong.

Tips
ping is a required built-in heartbeat endpoint. Keep it, do not delete it, and do not put time-consuming logic in it.
Backend service example
A micro-app with a backend service uses simplejrpc-go, a Unix Socket and JSON-RPC 2.0. The platform forwards requests that arrive at the unified entry point to the backend Socket, so the backend does not listen on an HTTP port itself.
1. Program entry point (backend/main.go)
func main() {
sock := common.DefaultSockPath()
// Create the RPC server and register services
server := rpc.NewServer()
// Start the service (blocks; exits gracefully on SIGINT/SIGTERM)
if err := server.Start(sock); err != nil {
core.Container.Log().Error(fmt.Sprintf("启动RPC服务器失败: %v", err))
return
}
}2. Register methods (internal/handler/rpc/server.go)
Every method the backend exposes has to be registered by name first:
func (s *Server) RegisterHandles(ds interface {
RegisterHandle(name string, handler func(*gsock.Request) (any, error), middlewares ...gsock.RPCMiddleware)
}) {
// Basic endpoints (ping is the platform health check; do not delete or change it)
ds.RegisterHandle("ping", s.Ping)
// Example module
ds.RegisterHandle("hello", s.Hello)
}3. Implement methods (internal/handler/rpc/example_handler.go)
A handler does only three things: parse the parameters, call the Service, return the result:
// Hello example endpoint: greeting
// Method: hello
// Params: lang (optional, language identifier), name (required, person name)
// Result: "hello {name}"
func (s *Server) Hello(req *gsock.Request) (any, error) {
// 1. Parse the parameters (sets the i18n language automatically)
var args dto.HelloReq
if err := rpcutil.ParseParams(req, &args); err != nil {
return nil, err
}
// 2. Validate the parameters
if args.Name == "" {
return nil, fmt.Errorf("%s", gi18n.Instance().T("NameRequired"))
}
// 3. Call the Service and return (the RPC service wraps the response automatically)
return exampleService().Hello(args)
}The matching Service implementation:
// Hello example endpoint: returns the greeting
func (s *ExampleService) Hello(args dto.HelloReq) (string, error) {
return fmt.Sprintf("hello %s", args.Name), nil
}Method details
| Method | Purpose |
|---|---|
ping | Platform health check heartbeat. Must be kept; returns pong. |
hello | Business example method that shows parameter parsing, validation and the Service call. |
Testing the endpoint
During development you can test backend methods through the unified entry point that the platform provides. The example below calls the hello method:

Request format
Call it with POST and a standard JSON body. The version and transport values below are examples; real frontend code reads them from the $gm object injected by the desktop and should never hard-code them in business code.
{
"version": "1.0.0",
"transport": "socket",
"params": {
"lang": "zh-CN",
"name": "world"
}
}Parameters
| Field | Type | Required | Description |
|---|---|---|---|
version | string | Yes | Request version between the platform and the app. The frontend reads it from window.$gm.version; do not fix it to a specific version number. |
transport | string | Yes | Transport type used by the platform. The frontend reads it from window.$gm.communicationType; for the Socket type the example value is socket. |
params | object | Depends on the method | Business parameter object. It is forwarded as the JSON-RPC parameters and parsed by the handler into the matching DTO; the hello method requires name. |
Response format
simplejrpc-go wraps the handler return value in a unified response. The full structure includes meta:
{
"code": 200,
"data": "hello world",
"msg": "OK",
"meta": {
"endpoint": "hello",
"close": 0
}
}Note
codeis the status code in the backend RPC response;200means success. When a handler returns an error the response has a code other than200.meta.endpointis the method name the backend actually handled, andmeta.closetells whether the Socket connection is kept open.
About authentication
Pages call the backend through $gm.request() and do not have to build a token by hand. If you request the desktop service directly from an external tool, you have to follow the authentication requirements of the desktop service itself; that is not part of the Go Socket RPC parameter format.
URL conventions
Pass a relative path to $gm.request():
/api/call/{org}/{app}/{method}Only when you use an external HTTP client do you prepend the desktop service address:
http://{desktop-service-address}/api/call/{org}/{app}/{method}For example, to call the hello method:
/api/call/official/example/helloURL parts:
official/example: the app identifier (org/app), which must matchAppNamein the backendconstant.go; the value here is an example.hello: the RPC method name registered by the backend throughRegisterHandle("hello", s.Hello).
Note
Make sure the app identifier matches the name you entered when you created the debug app. The name is case-sensitive.
Calling the backend from the frontend
Prerequisites
Before the frontend calls a backend endpoint, make sure that:
- The backend service is running and listening on the Socket;
- An app that has a backend service has called
$gm.init(); wait for initialization to complete before calling business endpoints.
The initialization example lives in web/index.html and is commented out by default. Enable it depending on whether your app has a backend service.
What it looks like

Code example
The frontend can call the backend hello method like this:
<button class="button12">Send request</button>
<script>
document.querySelector('.button12').addEventListener('click', function () {
$gm.request('/api/call/official/example/hello', {
method: 'post',
data: {
"version": window?.$gm?.version,
"transport": window?.$gm?.communicationType,
"params": {
"lang": "zh-CN",
"name": "world"
}
}
}).then(res => {
console.log(res)
$gm.message.success(res.data.data); // hello world
})
})
</script>Key points
- Unified entry point: the frontend always calls the backend through
/api/call/{org}/{app}/{method}and never has to know the Socket path or port; - Dynamic parameters:
versionandtransportare read from thewindow.$gmobject injected by the desktop; - Business parameters: the fields in
paramscorrespond to thejsontags of the backend DTO; - Two response layers: the value returned by a platform request is usually exposed as
res.dataof$gm.request(), and the backend business value sits inres.data.data. Do not mistake the outer HTTP response for the inner RPC response.
Access flow diagram
The access flow of an app looks like this:
Flow walkthrough
- The frontend sends a request: a user action triggers
$gm.request(), and the path carries the app identifier and the method name; - The platform unified entry point receives it: the platform looks up the target app by
official/example; - Forwarding to the Socket: the platform forwards the business request to the app's Unix Socket with the RPC method name
hello; - The handler parses the parameters:
rpcutil.ParseParams()parsesparamsinto the DTO and sets up i18n fromlang; - The Service runs the business logic: the handler calls the Service and gets
hello world; - The response is wrapped and returned:
simplejrpc-goproduces{code, data, msg, meta}and the platform returns the result to$gm.request(); - The frontend reads the business value: the frontend reads
hello worldfromres.data.dataand shows the message.
Socket path
In an installed layout the backend executable is app/bin/main and the Socket is tmp/app.sock in the root of the same app package. When you run it locally with go run, the Socket falls back to tmp/app.sock in the current directory. The frontend never needs to know this path.
