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

Adding support for providing dynamic headers to requests #66

Closed rmaclean-ee closed 6 years ago

rmaclean-ee commented 6 years ago

Related to https://github.com/christianmalek/vuex-rest-api/issues/36

This is to allow the use of dynamic headers to be passed through from the request by extending ShorthandResourceActionOptions with a property for headers. This property follows the same design as the path so it is Function|Object which lets you pass in a static or dynamic header.

Example usage of static header key and value

 .get({
    action: 'getData',
    property: 'stocks',
    path: '/stock',
    queryParams: false,
    headers: { 'X-Stock': 'MSFT' }
  })

Example usage of dynamic header value

 .get({
    action: 'getData',
    property: 'stocks',
    path: '/stock',
    queryParams: false,
    headers: ({ stockCode }) => ({ 'X-Stock': stockCode }),
  })

stockCode in the above example comes from the same parameter bag as would be used for paths.

christianmalek commented 6 years ago

Hello Robert,

Thanks for your contribution. I'm currently on vacation. I'll look into it in two weeks!

Robert MacLean notifications@github.com schrieb am Mo., 25. Juni 2018, 12:04:

Related to #36 https://github.com/christianmalek/vuex-rest-api/issues/36

This is to allow the use of dynamic headers to be passed through from the request by extending ShorthandResourceActionOptions with a property for headers. This property follows the same design as the path so it is Function|Object which lets you pass in a static or dynamic header.

Example usage of static header key and value

.get({ action: 'getData', property: 'stocks', path: '/stock', queryParams: false, headers: { 'X-Stock': 'MSFT' } })

Example usage of dynamic header value

.get({ action: 'getData', property: 'stocks', path: '/stock', queryParams: false, headers: ({ stockCode }) => ({ 'X-Stock': stockCode }), })

stockCode in the above example comes from the same parameter bag as would be used for paths.

You can view, comment on, or merge this pull request online at:

https://github.com/christianmalek/vuex-rest-api/pull/66 Commit Summary

  • Adding support for allowing headers to be passed in as an option
  • Updated distribution version

File Changes

Patch Links:

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/christianmalek/vuex-rest-api/pull/66, or mute the thread https://github.com/notifications/unsubscribe-auth/ACvaggpEyvWVesj9rXbbOPFVdrJk01cdks5uALW1gaJpZM4U13Ej .

christianmalek commented 6 years ago

Thanks @rmaclean-ee,

it's now available via version 2.8.0 :)