# Example rpc for initializer.RegisterHttp

**URL:** <https://forum.heroiclabs.com/t/example-rpc-for-initializer-registerhttp/6099>\
**Category:** Runtime Framework\
**Tags:** server-framework, golang\
**Created:** [March 18, 2025, 6:44am UTC](https://forum.heroiclabs.com/t/example-rpc-for-initializer-registerhttp/6099 "2025-03-18T06:44:52Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![hjs0n](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/hjs0n/32/2507_2.png) [@hjs0n](https://forum.heroiclabs.com/u/hjs0n)\
**Post date:** [March 18, 2025, 6:44am UTC](https://forum.heroiclabs.com/t/example-rpc-for-initializer-registerhttp/6099/1 "2025-03-18T06:44:52Z")

</div>

```auto
func GetLeaderBoardData(w http.ResponseWriter, r *http.Request) {
	body, err := io.ReadAll(r.Body)

	if err != nil {
		return
	}

//How?
	runtime.NakamaModule.LeaderboardRecordsList(, )
}

```

📺 **Media:**

Example rpc for initializer.RegisterHttp doesn’t exist. How exactly can I use it?

---

<div class="post-metadata">

**Author:** ![hjs0n](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/hjs0n/32/2507_2.png) [@hjs0n](https://forum.heroiclabs.com/u/hjs0n)\
**Post date:** [March 18, 2025, 7:33am UTC](https://forum.heroiclabs.com/t/example-rpc-for-initializer-registerhttp/6099/2 "2025-03-18T07:33:38Z")

</div>

```auto
type HttpHandler struct {
	Context context.Context
	NakamaModule runtime.NakamaModule
	Logger runtime.Logger
	DB *sql.DB
}

func (h *HttpHandler) GetLeaderBoardData(w http.ResponseWriter, r *http.Request) {}

```

That’s how I solved it. Is there a way to use a handler without making it like this?

---

<div class="post-metadata">

**Author:** ![sesposito](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/sesposito/32/2594_2.png) [@sesposito](https://forum.heroiclabs.com/u/sesposito)\
**Post date:** [March 18, 2025, 11:17am UTC](https://forum.heroiclabs.com/t/example-rpc-for-initializer-registerhttp/6099/3 "2025-03-18T11:17:12Z")

</div>

Hello @hjs0n,

`RegisterHttp` is meant for public (no auth) APIs, custom callback handlers or anything that requires lower-level control over the http request flow. We don’t yet have detailed documentation on this but there’s plenty of resources that cover this topic online as it follows the standard Go Http handler interface.

If you do not require the above, the standard way to have custom APIs in Nakama is using [RegisterRpc](https://heroiclabs.com/docs/nakama/server-framework/introduction/index.html#rpc-functions).

If this is not what you’re looking for, please clarify what you’re trying to achieve.

You can also have a look at our [template project](https://github.com/heroiclabs/nakama-project-template) to get started.

Best.

---

<div class="post-metadata">

**Author:** ![hjs0n](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/hjs0n/32/2507_2.png) [@hjs0n](https://forum.heroiclabs.com/u/hjs0n)\
**Post date:** [March 19, 2025, 1:03am UTC](https://forum.heroiclabs.com/t/example-rpc-for-initializer-registerhttp/6099/4 "2025-03-19T01:03:44Z")

</div>

Hello, @sesposito

What I want is to get data such as storage, leaderboard, etc. using rpc without authentication. I thought registerHttp could use it like that. If I use registerRpc, I have to create an account for dummy, but I don’t want to. Is there any other way?

---

<div class="post-metadata">

**Author:** ![hjs0n](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/hjs0n/32/2507_2.png) [@hjs0n](https://forum.heroiclabs.com/u/hjs0n)\
**Post date:** [March 19, 2025, 3:42am UTC](https://forum.heroiclabs.com/t/example-rpc-for-initializer-registerhttp/6099/5 "2025-03-19T03:42:53Z")

</div>

And it works well with the code above, is there a problem? If there is a problem, please let me know another way.

---

<div class="post-metadata">

**Author:** ![sesposito](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/sesposito/32/2594_2.png) [@sesposito](https://forum.heroiclabs.com/u/sesposito)\
**Post date:** [March 19, 2025, 11:53am UTC](https://forum.heroiclabs.com/t/example-rpc-for-initializer-registerhttp/6099/6 "2025-03-19T11:53:58Z")

</div>

Ok if you’d like to bypass Nakama standard auth then yeah, RegisterHttp is the way to go, I see no issue with the approach I just wanted to make sure you’re aware that the endpoints will be publicly accessible.

---

<div class="post-metadata">

**Author:** ![hjs0n](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/hjs0n/32/2507_2.png) [@hjs0n](https://forum.heroiclabs.com/u/hjs0n)\
**Post date:** [March 20, 2025, 1:58am UTC](https://forum.heroiclabs.com/t/example-rpc-for-initializer-registerhttp/6099/7 "2025-03-20T01:58:28Z")

</div>

```auto
type HttpHandler struct {
	NakamaModule runtime.NakamaModule
	Logger runtime.Logger
}

func InitModule(ctx context.Context, logger runtime.Logger, db *sql.DB, nk runtime.NakamaModule, initializer runtime.Initializer) error {
	logger.Info("Hello World!")

	handler := &HttpHandler{
		NakamaModule: nk,
		Logger: logger,
	}
}

```

Is there any problem with creating global structure instances when doing InitModule like above, except for having open access to endpoints?  
I really don’t know if that’s the best way.

---

<div class="post-metadata">

**Author:** ![sesposito](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/sesposito/32/2594_2.png) [@sesposito](https://forum.heroiclabs.com/u/sesposito)\
**Post date:** [March 20, 2025, 11:15am UTC](https://forum.heroiclabs.com/t/example-rpc-for-initializer-registerhttp/6099/8 "2025-03-20T11:15:02Z")

</div>

There shouldn’t be an issue, if you want to avoid the global struct you can use a closure to pass the required dependencies to the handlers.

---

<div class="post-metadata">

**Author:** ![hjs0n](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/hjs0n/32/2507_2.png) [@hjs0n](https://forum.heroiclabs.com/u/hjs0n)\
**Post date:** [March 21, 2025, 1:03am UTC](https://forum.heroiclabs.com/t/example-rpc-for-initializer-registerhttp/6099/9 "2025-03-21T01:03:07Z")

</div>

Ok, Thank you for your response.
