Skip to content

Return Types

Handlers in Xin can return several different types of values. These are automatically normalized into proper HTTP responses.

  • JSX → rendered to HTML (text/html)
  • string / number → returned as text/plain
  • object → returned as application/json
  • Response → passed through as‑is
  • null / undefined204 No Content

Returns an HTML response.

api.get(() => {
return <h1>Hello from JSX!</h1>
})

Returns a text/plain response. Numbers are converted to strings.

api.get(() => 'Ok')
api.get(() => 42)

Returns an application/json response.

api.get(() => {
return {
"message": "Hello World!"
}
})

You can also return a raw Response if you need full control.

api.get(() => {
return new Response("Custom", { status: 202 })
})

Returning null or undefined results in a 204 No Content response.

api.get(() => null)