christianmalek / vuex-rest-api

A utility to simplify the use of REST APIs with Vuex
http://vuex-rest-api.org
MIT License
382 stars 48 forks source link

Request/Suggestion - path parameters vs query parameters #44

Closed dboune closed 6 years ago

dboune commented 6 years ago

I believe it would be helpful if there were either a way to filter the params prior to passing them to axios but after using them in the path without using paramsSerializer, or if they were just considered two separate things entirely. I would prefer the latter.

Unless I've missed something, without importing a serializer like qs and using it in paramsSerializer it does not seem possible to strip params that have been used in the path.

The following results in a URL like: /projects/{projectId}/participants?projectId={projectId}&active=1

.get({
  action: 'getProjectParticipants',
  property: 'participants',
  queryParams: true,
  path: { projectId } => `/projects/${projectId}/participants`
})
getProjectParticipants({
  params: {
    projectId: '123',
    active: '1'
  }
})

Something like the following would feel more intuitive to me. (I'm not intending to suggest key names)

.get({
  action: 'getProjectParticipants',
  property: 'participants',
  path: { projectId } => `/projects/${projectId}/participants`
})
getProjectParticipants({
  path: {
    projectId: '123',
  },
  query: {
    active: '1'
  }
})
christianmalek commented 6 years ago

Hello Damian,

Thank you for your request. The decision of passing query parameters to the request URL or appending the data to the body is made during the Resource creation. So at the moment it's not possible to react on your suggested query property to only use query parameters when this field is set.

It could be possible to apply your suggestion, e.g. by wrapping the Resource.requestFn in an additional function. But I don't going to implement this in v2 anymore. I'm sorry. I'll remember it for v3.

christianmalek commented 6 years ago

I've added it to #57 and will close this issue. Feel free to open a new one.