Skip to content
Myr

feat: add first-class QUERY method support (#5070)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by haki · committed by Yusuke Wada · parent 5fc8aad · Browse files · 5 files+45 added−2 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

5 files+45 added−2 removed

  • tests:+42 added−0 removed
  • other:+3 added−2 removed

5 files+45 added−2 removed

modified:src/client/types.test.ts+1 added
modified:src/client/types.ts+1 added-1 removed
10 unmodified lines
11type MethodNameAll = `$${typeof METHOD_NAME_ALL_LOWERCASE}`1213/**14 * Type representing all standard HTTP methods prefixed with '$'15 * e.g., '$get' | '$post' | '$put' | '$delete' | '$options' | '$patch'15 * e.g., '$get' | '$post' | '$put' | '$delete' | '$options' | '$patch' | '$query'16 */17type StandardMethods = `$${(typeof METHODS)[number]}`1819/**
374 unmodified lines
modified:src/hono-base.ts+1 added
105 unmodified lines
106 put!: HandlerInterface<E, 'put', S, BasePath, CurrentPath>107 delete!: HandlerInterface<E, 'delete', S, BasePath, CurrentPath>108 options!: HandlerInterface<E, 'options', S, BasePath, CurrentPath>109 patch!: HandlerInterface<E, 'patch', S, BasePath, CurrentPath>110 query!: HandlerInterface<E, 'query', S, BasePath, CurrentPath>111 all!: HandlerInterface<E, 'all', S, BasePath, CurrentPath>112 on: OnHandlerInterface<E, S, BasePath>113 use: MiddlewareHandlerInterface<E, S, BasePath>114
432 unmodified lines
modified:src/hono.test.ts+41 added
2077 unmodified lines
2078 expect(res.status).toBe(404)2079 })2080})20812082describe('Using QUERY with `app.query` and `app.on`', () => {2083 it('Should handle QUERY method with app.query()', async () => {2084 const app = new Hono()20852086 app.query('/query', (c) => c.text('Accepted', 202))20872088 const req = new Request('http://localhost/query', {2089 method: 'QUERY',2090 })2091 const res = await app.request(req)2092 expect(res.status).toBe(202)2093 expect(await res.text()).toBe('Accepted')2094 })20952096 it('Should handle QUERY method with RegExpRouter', async () => {2097 const app = new Hono({ router: new RegExpRouter() })20982099 app.on('QUERY', '/query', (c) => c.text('Accepted', 202))21002101 const req = new Request('http://localhost/query', {2102 method: 'QUERY',2103 })2104 const res = await app.request(req)2105 expect(res.status).toBe(202)2106 expect(await res.text()).toBe('Accepted')2107 })21082109 it('Should handle QUERY method with TrieRouter', async () => {2110 const app = new Hono({ router: new TrieRouter() })21112112 app.on('QUERY', '/query', (c) => c.text('Accepted', 202))21132114 const req = new Request('http://localhost/query', {2115 method: 'QUERY',2116 })2117 const res = await app.request(req)2118 expect(res.status).toBe(202)2119 expect(await res.text()).toBe('Accepted')2120 })2121})21222123describe('Multiple paths with one handler', () => {2124 const app = new Hono()21252126 const paths = ['/hello', '/ja/hello', '/en/hello']
1674 unmodified lines
modified:src/router.ts+1 added-1 removed
12 unmodified lines
13export const METHOD_NAME_ALL_LOWERCASE = 'all' as const14/**15 * Array of supported HTTP methods.16 */17export const METHODS = ['get', 'post', 'put', 'delete', 'options', 'patch'] as const17export const METHODS = ['get', 'post', 'put', 'delete', 'options', 'patch', 'query'] as const18/**19 * Error message indicating that a route cannot be added because the matcher is already built.20 */21export const MESSAGE_MATCHER_IS_ALREADY_BUILT =
82 unmodified lines