Which solution comes to mind to when you control the client and the server.
You want to share types between front-end and back-end.
Right now I have a Hono server and I call this from my client using fetch.
And I cheat by saying “trust me bro” using
external fromJson: Js.Json.t => 't = "%identity"
external toJson: 't => Js.Json.t = "%identity"
// On the client
let response = await fetch(
url,
{
method: #POST,
headers: Headers.fromObject({
"Content-Type": "application/json",
}),
body: reqData
->toJson
->JSON.stringify
->Body.string,
},
)
let json = await response->Response.json
let resData: vrindelyckResponse = fromJson(json)
// On the server
app
->Hono.post(route, async ctx => {
let json = await ctx->Context.req->Request.json
let requestData = json->fromJson
I mean, this all works, but do I really care how this is done on the http level?
The fact that my endpoint is a POST for example.
I just want to invoke something on the server, and get that return type.
Does anything come to mind to solve this?