Make postman query param type of boolean

2178 views javascript
5

I use postman to test my api

http://localhost:3000/api/books?disabled=true

I want to set disabled=true (or false) and I expect it is a bool

But somehow

const {disabled} = req.query;
console.log(typeof disabled) //I get disabled type of string

How I set my query param boolean type?

answered question

Have you tired to set disabled to 1 or 0 ?

It still shows that type of disabled is string

Just asking, won't it work with a boolean? like let condition = disabled==='true'?

1 Answer

3

Regardless of the format (query params, JSON body) it is the job of the backend to parse and validate the request.

So even if you send a parameter like “active=true”, it is still a string, this is how the HTTP protocol works.

For more info ---> https://community.getpostman.com/t/how-to-pass-boolean-values-using-postman/1174

posted this

Have an answer?

JD

Please login first before posting an answer.