Git Product home page Git Product logo

Comments (8)

christianmalek avatar christianmalek commented on May 28, 2024 1

Maybe, params object should not be set if requestConfig object is not contain paramsSerializer function.

Great idea. I'll change this tomorrow and let you know!

Then will be better specify paramsSerializer in the ResourceWrapper

If I add the check constraint it is indifferent if you just do it on one action or the axios instance.

from vuex-rest-api.

christianmalek avatar christianmalek commented on May 28, 2024

Your code should work. Alternatively you can pass each action a request config. The property's name is requestConfig.

Example:

  resource.addAction({
    action: "get",
    method: "get",
    property: "post",
    pathFn: ({ id }) => `/posts/${id}`,
    requestConfig: {
            paramsSerializer: function(params) {
                return Qs.stringify(params, {arrayFormat: 'indices'})
            }
    }
});

from vuex-rest-api.

elceka avatar elceka commented on May 28, 2024

Thank you for fast reply, but that solutions (yours and my) wont work. HTTP request is without params of the URL.

from vuex-rest-api.

christianmalek avatar christianmalek commented on May 28, 2024

I'll investigate this issue later today.

from vuex-rest-api.

christianmalek avatar christianmalek commented on May 28, 2024

@elceka Please update your npm package.

from vuex-rest-api.

elceka avatar elceka commented on May 28, 2024

Thank you, its working.
But now, all actions have set request config, but i set this option only in action for list of models.

Example of store:

import { stringify } from 'qs'
import { createStore } from 'vuex-rest-api'
import ResourceWrapper from './../ResourceWrapper'

const resource = new ResourceWrapper()
    .addAction({
        action: 'listModels',
        method: 'get',
        property: 'models',
        pathFn: () => `/models`,
        requestConfig: {
            paramsSerializer: function (params) {
                return stringify(params, {arrayFormat: 'indices'})
            }
        }
    })
    .addAction({
        action: 'getModel',
        method: 'get',
        property: 'model',
        pathFn: ({ id }) => `/models/${id}`
    })
    .addAction({
        action: 'createModel',
        method: 'post',
        property: 'model',
        pathFn: () => `/models`
    })

const models = createStore(resource)

export default models

Produced URL for getting one model:

GET http://localhost:8003/api/admin/models/45c6d991-34fc-321f-a2e2-3b921b35a6a1?id=45c6d991-34fc-321f-a2e2-3b921b35a6a1

from vuex-rest-api.

elceka avatar elceka commented on May 28, 2024

Issue is on this new line of code from Resource class:

const requestConfig = Object.assign({}, options.requestConfig, { params: params });

Maybe, params object should not be set if requestConfig object is not contain paramsSerializer function.
Or, specify all parameters for paramsSerializer function on action of store:

const resource = new ResourceWrapper()
    .addAction({
        action: 'listModels',
        method: 'get',
        property: 'models',
        pathFn: () => `/models`,
        requestConfig: {
            paramsSerializer: function ({limit, page, sort}) {
                return stringify({limit, page, sort}, {arrayFormat: 'indices'})
            }
        }
    })
...

Then will be better specify paramsSerializer in the ResourceWrapper:

...
    options.axios = Axios.create({
        headers: {
            'Accept': 'application/json',
            'Authorization': 'Basic abc...='
        },
        paramsSerializer: function ({limit, page, sort}) {
            return stringify({limit, page, sort}, {arrayFormat: 'indices'})
        }
    })
...

from vuex-rest-api.

elceka avatar elceka commented on May 28, 2024

Thank you again, it is working, all is only about implementation.

from vuex-rest-api.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.