Skip to content

Conversation

@ysknsid25
Copy link
Contributor

@ysknsid25 ysknsid25 commented Dec 6, 2025

resolves: #51

  • Pretty Format
  • -o <path> and -O
  • -J and --json
  • -i and -I

Sample

app.ts

import { Hono } from 'hono'
import { readFile } from 'node:fs/promises'
import { join } from 'node:path'

const app = new Hono()

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

app.get('/text', (c) => {
  return c.text('This is a plain text response.')
})

app.get('/image.png', async (c) => {
  try {
    const imagePath = join(process.cwd(), 'src', 'image.png')
    const imageData = await readFile(imagePath)
    return c.body(imageData.buffer, 200, {
      'Content-Type': 'image/png',
    })
  } catch (error) {
    console.error('Error serving image:', error)
    return c.text('Image not found', 404)
  }
})

export default app

use this png image

image

Default(Pretty Format)

node ./dist/cli.js request ./src/app.ts

image

Binary Response & not save

node ./dist/cli.js request ./src/app.ts -P /image.png

image

JSON Response & -o <path>

node ./dist/cli.js request ./src/app.ts -o index.json

image

JSON Response & -O

node ./dist/cli.js request ./src/app.ts -P /text -O

image

Binary Response & -o <path>

node ./dist/cli.js request ./src/app.ts -P /image.png -o test.png

image

Binary Response & -O

node ./dist/cli.js request ./src/app.ts -P /image.png -O

image

-J and --json

node ./dist/cli.js request ./src/app.ts -J

image

-I

node ./dist/cli.js request ./src/app.ts -I

image

-i

node ./dist/cli.js request ./src/app.ts -J -i

image

Signed-off-by: ysknsid25 <kengo071225@gmail.com>
fix test

Signed-off-by: ysknsid25 <kengo071225@gmail.com>
@ysknsid25 ysknsid25 marked this pull request as draft December 6, 2025 07:39
@ysknsid25 ysknsid25 marked this pull request as ready for review December 6, 2025 07:39
fix function name `parsedResponseBody`

Signed-off-by: ysknsid25 <kengo071225@gmail.com>
fix README

Signed-off-by: ysknsid25 <kengo071225@gmail.com>
@ysknsid25 ysknsid25 marked this pull request as draft December 6, 2025 07:48
fix output format when direct`exclude`

Signed-off-by: ysknsid25 <kengo071225@gmail.com>
@ysknsid25 ysknsid25 marked this pull request as ready for review December 6, 2025 11:23
Signed-off-by: ysknsid25 <kengo071225@gmail.com>
@pkg-pr-new
Copy link

pkg-pr-new bot commented Jan 5, 2026

Open in StackBlitz

npm i https://pkg.pr.new/@hono/cli@58

commit: 253b360

Signed-off-by: ysknsid25 <kengo071225@gmail.com>
@ysknsid25 ysknsid25 changed the title feat(request): Improve hono request output [WIP 2/4] feat(request): Improve hono request output Jan 5, 2026
@ysknsid25 ysknsid25 changed the title [WIP 2/4] feat(request): Improve hono request output [WIP] feat(request): Improve hono request output Jan 5, 2026
@ysknsid25 ysknsid25 marked this pull request as draft January 5, 2026 13:24
@yusukebe
Copy link
Member

yusukebe commented Jan 6, 2026

Hey @ysknsid25

If it's ready to review, please ping me!

@ysknsid25
Copy link
Contributor Author

@yusukebe
A Happy New Year @yusukebe 🎍
Okey, dokey 🫡

Signed-off-by: ysknsid25 <kengo071225@gmail.com>
Signed-off-by: ysknsid25 <kengo071225@gmail.com>
Signed-off-by: ysknsid25 <kengo071225@gmail.com>
Signed-off-by: ysknsid25 <kengo071225@gmail.com>
resolve [object Object] when console.log to terminal

Signed-off-by: ysknsid25 <kengo071225@gmail.com>
@ysknsid25 ysknsid25 changed the title [WIP] feat(request): Improve hono request output feat(request): Improve hono request output Jan 13, 2026
@ysknsid25 ysknsid25 marked this pull request as ready for review January 13, 2026 10:29
@ysknsid25
Copy link
Contributor Author

@yusukebe
Sorry for the wait 🙇
Please review 🙏🙏🙏

@yusukebe yusukebe changed the title feat(request): Improve hono request output feat(request)!: Improve hono request output Jan 13, 2026
import { existsSync, createWriteStream } from 'node:fs'
import { dirname, basename } from 'node:path'

export const getFilenameFromPath = (path: string): string => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With the current implementation, if the path is /, the file name will be blank, and an error will occur.

Error saving file: ENOENT: no such file or directory, open ''

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried setting a default filename. When request to / and direct --remote-name, / is named index.
What do you think?👀

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally, adding an extension that depends on the content type is best. For example, if the content is application/json, the name will be index.json.

Plus, it's not just about this issue; should we also check whether the same file name exists in the current directory and avoid overwriting?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For json, html, xml, and txt, which are likely to be responses for /, we have tried to add extensions based on the contentType 👀

We have also implemented overwrite prevention.

@yusukebe
Copy link
Member

@ysknsid25 Thank you! I left some comments.

Hey @usualoma Can you also review this, if you have time!

Copy link
Member

@usualoma usualoma left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the great work!
I've added one comment.

fix return to continue

Signed-off-by: ysknsid25 <kengo071225@gmail.com>
To be able to handle `application/json; charset=utf-8`

Signed-off-by: ysknsid25 <kengo071225@gmail.com>
show more rich http header

Signed-off-by: ysknsid25 <kengo071225@gmail.com>
fix `formatResponseBody()` return type. string to string | object

Signed-off-by: ysknsid25 <kengo071225@gmail.com>
To be able to save when request to /

Signed-off-by: ysknsid25 <kengo071225@gmail.com>
Signed-off-by: ysknsid25 <kengo071225@gmail.com>
Copy link
Member

@usualoma usualoma left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

fix indexOf to regular expressions

Signed-off-by: ysknsid25 <kengo071225@gmail.com>
For some contentTypes, set the extension

Signed-off-by: ysknsid25 <kengo071225@gmail.com>
@ysknsid25 ysknsid25 requested a review from yusukebe January 23, 2026 08:34
@ysknsid25 ysknsid25 changed the title feat(request)!: Improve hono request output feat(request): Improve hono request output Jan 23, 2026
Signed-off-by: ysknsid25 <kengo071225@gmail.com>
For some contentTypes, set the extension by using `hono/utils/mime`

Signed-off-by: ysknsid25 <kengo071225@gmail.com>
@ysknsid25 ysknsid25 requested a review from yusukebe January 31, 2026 05:44
Copy link
Member

@yusukebe yusukebe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@yusukebe
Copy link
Member

@ysknsid25

Looks good! Let's land it. Thank you for your great work!

@yusukebe yusukebe merged commit 2cc72ba into honojs:main Jan 31, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Improve hono request output

3 participants