elbywan / wretch

A tiny wrapper built around fetch with an intuitive syntax. :candy:
MIT License
4.79k stars 96 forks source link

send a string in a post request #130

Closed ahtd3 closed 2 years ago

ahtd3 commented 2 years ago

I'm new in wretch When using a post request with body, everything works fine to me

const postRequest = (clientId: string) => request.url(EP.postRequest)
            .post({ clientId })
            .json(handleResponse)
            .catch(handleError)

but if I want to send a string only (.post(clientId)) instead of creating a new model like above (post({ clientId }))

const postRequest = (clientId: string) => request.url(EP.postRequest)
            .post(clientId)
            .json(handleResponse)
            .catch(handleError)

the backend responses a 415 response status code

here's what I defined to API endpoint in backend (using dotnet core)

[HttpPost("PostRequest")]
public async Task<bool> PostRequest(string clientId) {  }

so what was I wrong in my code? please give me any explain. thanks

elbywan commented 2 years ago

Hey @ahtd3,

I do not see anything wrong regarding the wretch code:

wretch()
    .url("/")
    .post("hello")
    .text(console.log)
    .catch(console.error)
Capture d’écran 2022-04-18 à 19 53 34

I assume that the issue comes from the .net code, so I will close the issue since it is not related to the library.