Skip to content

Improve hono request output #51

@yusukebe

Description

@yusukebe

Currently, the hono request output format is as follows:

{
  "status": 200,
  "body": "content"
  "headers": {}
}

We have room for reconsideration and improvement.

One problem is that if the application returns JSON, the result is like this:

The app:

import { Hono } from 'hono.'

const app = new Hono()

app.get('/', (c) => {
  return c.json({
    message: 'Hello'
  })
})

export default app

The output:

{
  "status": 200,
  "body": "{\"message\":\"Hello\"}",
  "headers": {
    "content-type": "application/json"
  }
}

The body {\"message\":\"Hello\"} is expected format?? I think no. It should not be escaped. And more! Should status and headers be included in the output? Following curl, the output should be only the body content by default:

curl http://localhost:7070
{"message": "Hello"}

Perhaps following curl is okay, adding an option like -I. On the other hand, JSON is beneficial to parse with jq or a simpler command. But regarding this, it's okay to add the option like --json or (-w '%{json}' looks interesting but verbose).

Anyway, we have to consider the output format of hono request.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions