aspida / aspida

TypeScript friendly HTTP client wrapper for the browser and node.js.

Home Page:https://github.com/aspida/aspida

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Specifying query parameter order

matamatanot opened this issue · comments

Description

In order for caching to work efficiently, clients should use the same URLs; if the App and Web refer to the same resources, but the order of the query parameters is different, caching will often not work.

eg
/user/?type=1&class=2
/user/?class=2&type=1

The resource that the URL asks for is the same, but the cache may not work.

Alphabetical order, for example, seems to be easy to implement. However, in some cases, there are unique rules that require the order to be specified.

Describe the solution you'd like

Add a new property to type definition files.
queryOrder: ['class', 'type']

Describe alternatives you've considered

Additional context

commented

We're sorry for the late response.

there are unique rules that require the order to be specified

hm.. I can confirm sensing order of query is not illegal as http server. Can you let me know example?

Aspida is mainly for JSON API, so query also wanted to be treated as JSON dictionary, so this is prioritized very low. queryOrder: ['class', 'type'] is acceptable idea. We're welcome PRs. Thank you.

commented

How about followings?

api.some.path.$get({
  query: {
    param1: 'foo',
    param2: 'bar',
  },
})

or

api.some.path.$get({
  query: {
    param1: query.param1,
    param2: query.param2,
  },
})

These maybe can fix the order of query param.
We can write this as document, but I think it is not good pattern to use declaration order as specification of order of something.
If others think so and need ordering mechanism, please react as 😕 to this comment or write down details of your opinion.