elysiajs / eden

Fully type-safe Elysia client
MIT License
173 stars 41 forks source link

Because Elysia uses `fast-querystring` to decode, treaty should use it to encode #79

Closed MatthewAry closed 7 months ago

MatthewAry commented 7 months ago

fast-querystring introduces several benefits when used to encode query strings:

Unsafe URL characters are automatically encoded such that they are not misinterpreted by the server Suppose an endpoint has t.String({ format: 'email' }) on the query validator. If you tried to set the query string to test+1@test.com validation would fail because for some reason, the server would see the value as test+ @test.com or something. See: https://stackoverflow.com/questions/2322764/what-characters-must-be-escaped-in-an-http-query-string By using this package we solve this problem with minimal impact to perf.

Able to encode arrays Looking at the example posted on the readme in the fast-querystring repo:

const qs = require('fast-querystring')

// Parsing a querystring
console.log(qs.parse('hello=world&foo=bar&values=v1&values=v2'))
// {
//   hello: 'world',
//   foo: 'bar',
//   values: ['v1', 'v2']
// }

// Stringifying an object
console.log(qs.stringify({ foo: ['bar', 'baz'] }))
// 'foo=bar&foo=baz'

We see that fast-querystring will also handle arrays. This is helpful when you have situations where you might want to apply multiple filters to a data-table component and much more.

SaltyAom commented 7 months ago

Thank you for your contribution, but I chose to got with #84 which doesn't add an extra dependency to save some space.

Feels free to open an issue if further discussion need.