Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong format of POST request body data #201

Open
sytolk opened this issue Nov 10, 2017 · 0 comments
Open

Wrong format of POST request body data #201

sytolk opened this issue Nov 10, 2017 · 0 comments

Comments

@sytolk
Copy link

sytolk commented Nov 10, 2017

I have POST Endpoint from WS that accept application/x-www-form-urlencoded

"consumes": [
                    "application/x-www-form-urlencoded"
                ]

and generated React client

CodeGen.getReactCode({
    moduleName: className,
    className,
    swagger,
    isES6: true
});

When I call this request header Content-Type: application/x-www-form-urlencoded is missing and body data is JSON formatted {param1=.., param2=..} instead of: param1=..,param2=..

this is the fetch request in my generated code. Body is always JSON string

fetch(urlWithParams, {
            method,
            headers,
            body: JSON.stringify(body)
        })

My ugly quickfix is:

if (body && !Object.keys(body).length) {
            body = form;
        }

        fetch(urlWithParams, {
            method,
            headers,
            body: Object.keys(body).map(key=>encodeURIComponent(key)+'='+encodeURIComponent(body[key])).join('&')
        })

source: https://stackoverflow.com/a/37562814/2285631

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant