You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

@hono/client

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@hono/client

HTTP Client for Hono

0.0.3
latest
Source
npmnpm
Version published
Weekly downloads
631
80.29%
Maintainers
1
Weekly downloads
 
Created
Source

Hono Client

Version Bundle Size Bundle Size

Hono Client is HTTP Client based on Fetch API. It's Type-Safe. You can access to the Hono application ultra-easily.

import { Client } from '@hono/client'
import type { AppType } from './server'

const client = new Client<AppType>('http://localhost:8787/api')

const res = await client.post('/posts').json({
  id: 123,
  title: 'Hello Hono!',
  published: true,
})

const data = await res.json()
console.log(`${data.message}`)

Features

  • Small about 1.5kb
  • TypeSafe
  • Compatible with Fetch API
  • Optimized for Hono v3.x

Demo

Demo

Install

npm i @hono/client

Or

yarn add @hono/client

Examples

Server-side with Zod.

import { Hono } from 'hono'
import { validator } from 'hono/validator'
import { z } from 'zod'

const api = new Hono()

const schema = z.object({
  id: z.number(),
  title: z.string(),
  published: z.boolean(),
})

const route = api
  .post(
    '/posts',
    validator('json', (value, c) => {
      const result = schema.safeParse(value)
      if (!result.success) {
        return c.text('Invalid!', 400)
      }
      return result.data
    }),
    (c) => {
      const { title, published } = c.req.valid()
      return c.jsonT({
        success: true,
        message: `"${title}" is ${published ? 'published' : 'not published'}`,
      })
    }
  )
  .build()

export type AppType = typeof route

Author

Yusuke Wada https://github.com/yusukebe

License

MIT

FAQs

Package last updated on 31 Dec 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts