Skip to content

Encode request data as JSON when Content-Type is set to application/json #118

@jonkoops

Description

@jonkoops

When the the Content-Type header of a request is set to application/json shouldn't the request data be converted to a JSON string using JSON.stringify?

Currently I'm sending my requests like this:

reqwest({
    url: '/api/v1/user',
    type: 'json',
    method: 'post',
    contentType: 'application/json',
    processData: false,
    data: JSON.stringify({
        first_name: 'John',
        last_name: 'Doe'
    })
});

But it would be easier if I could do this:

reqwest({
    url: '/api/v1/user',
    type: 'json',
    method: 'post',
    contentType: 'application/json',
    data: {
        first_name: 'John',
        last_name: 'Doe'
    }
});

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions