cujojs / rest

RESTful HTTP client for JavaScript
http://cujojs.com/
Other
1k stars 146 forks source link

Change params order in template interceptor mixin function. #179

Closed illuminatedspace closed 6 years ago

illuminatedspace commented 6 years ago

This PR changes the order the params are merged so that the template interceptor config params can be overwritten by the request params.

The docs for template interceptor defines the config params property as:

default params to be combined with request.params

The template config params should be a default, as in they can be overwritten by the request.params. However the template config params cannot be overwritten by the request params.

This is the behavior I expected from reading the docs:

var client = rest.wrap(template, { params: { lang: 'en-us', section: 'introduction' } })

client({
  path: '/example/path/{section}{?lang}',
  params: {
    section: 'glossary'
  }
})

// response.url -> /example/path/glossary?lang=en-us

This is current behavior:

var client = rest.wrap(template, { params: { lang: 'en-us', section: 'introduction' } })

client({
  path: '/example/path/{section}{?lang}',
  params: {
    section: 'glossary'
  }
})

// response.url -> /example/path/introduction?lang=en-us
illuminatedspace commented 6 years ago

Fixing PR to follow the Contributor guidelines.