How does the REST API take boolean values?

A resource 123has a current configuration state and a default configuration state, and both of these configuration states can be represented by JSON.

A GETrequest http://example.com/123/configwill return the current configuration state, and a request GETto http://example.com/123/config?reset=truereturn the default configuration state.

How should the API interpret boolean values? For instance:

  • http://example.com/123/config?reset=true
  • http://example.com/123/config?reset=blablabla
  • http://example.com/123/config?reset=false
  • http://example.com/123/config?reset=1
  • http://example.com/123/config?reset=0
  • http://example.com/123/config?reset=
  • http://example.com/123/config?reset
+9
source share
2 answers

, /. true/false , , , .

+9

true false . , API JSON, true false, , .

, . .

, : CSS, overflow visibility. true false. , .

, , , , status, , default current.

:

GET /config?status=default HTTP/1.1
Host: example.com
Accept: application/json

:

GET /config?status=current HTTP/1.1
Host: example.com
Accept: application/json

, , .


, PUT, . - :

PUT /config/status HTTP/1.1
Host: example.com
Content-Type: application/json

{ 
  "value": "default" 
}
+9

Source: https://habr.com/ru/post/1657402/


All Articles