Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to pass boolean parameters to a restful service?

Tags:

rest

wcf

api

What is the best way to pass boolean parameters to a WCF RESTful service?

Using trueor false like this:

api/resource?hasProperty=true

or using 0 or 1 like this:

api/resource?hasProperty=1

like image 874
Sven Schelfaut Avatar asked Jan 21 '14 09:01

Sven Schelfaut


People also ask

Can you pass bool in JSON?

JSON BooleansValues in JSON can be true/false.

Why you shouldn't use booleans in rest APIS?

If not carefully considered, booleans can: Obstruct API Extensibility. Mask and obfuscate Domain Clarity. Hamper Code Readability and Maintainability.

How can the postman pass Boolean values?

So even if you send a parameter like “active=true”, it is still a string, this is how the HTTP protocol works. Hope this helps clarify the mystery. var bflag = Boolean(“true”); var bflag1 = Boolean(“false”);

How do I pass a Boolean parameter to a PowerShell script?

You can set the data type of your parameter to [bool] to pass Boolean values to a PowerShell script from a command prompt. Copy param([int]$a, [bool]$b) switch($b){ $true {"It is true."} $false {"It is false."} } Boolean parameters accept only Boolean values and numbers, such as $True , $False , 1 or 0 .


1 Answers

I like the

api/resource?hasProperty=true

approach because it is more user-friendly.

It tells the API consumer indirectly that it is a boolean parameter. 0 or 1 does not imply that.

like image 181
Santanu Dey Avatar answered Oct 05 '22 22:10

Santanu Dey