Skip to content

Commit da66f55

Browse files
docs: documentation for http int response as a string (#132)
Signed-off-by: James Milligan <[email protected]> Co-authored-by: Michael Beemer <[email protected]>
1 parent 63020fe commit da66f55

File tree

2 files changed

+113
-16
lines changed

2 files changed

+113
-16
lines changed

README.md

Lines changed: 91 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,32 +16,107 @@ Flagd is a simple command line tool for fetching and presenting feature flags to
1616
3. Start the process: `./flagd start -f config/samples/example_flags.json --service-provider http --sync-provider filepath`
1717

1818
This now provides an accessible http or [https](#https) endpoint for the flags:
19+
### Resolve a boolean value
1920

21+
Command:
22+
```sh
23+
curl -X POST "localhost:8013/flags/myBoolFlag/resolve/boolean"
2024
```
21-
$ curl -X POST "localhost:8013/flags/myBoolFlag/resolve/boolean"
22-
// {"value":true,"reason":"STATIC","variant":"on"}
25+
Result:
26+
```sh
27+
{"value":true,"reason":"STATIC","variant":"on"}
28+
```
29+
<br />
2330

24-
$ curl -X POST "localhost:8013/flags/myStringFlag/resolve/string"
25-
// {"value":"val1","reason":"STATIC","variant":"key1"}
31+
### Resolve a string value
2632

27-
$ curl -X POST "localhost:8013/flags/myIntFlag/resolve/int"
28-
// {"value":"1","reason":"STATIC","variant":"one"}
33+
Command:
34+
```sh
35+
curl -X POST "localhost:8013/flags/myStringFlag/resolve/string"
36+
```
37+
Result:
38+
```sh
39+
{"value":"val1","reason":"STATIC","variant":"key1"}
40+
```
41+
<br />
2942

30-
$ curl -X POST "localhost:8013/flags/myFloatFlag/resolve/float"
31-
// {"value":1.23,"reason":"STATIC","variant":"one"}
43+
### Resolve a integer value
3244

33-
$ curl -X POST "localhost:8013/flags/myObjectFlag/resolve/object"
34-
// {"value":{"key":"val"},"reason":"STATIC","variant":"object1"}
45+
Command:
46+
```sh
47+
curl -X POST "localhost:8013/flags/myIntFlag/resolve/int"
48+
```
49+
Result:
50+
```sh
51+
{"value":"1","reason":"STATIC","variant":"one"}
52+
```
53+
[Why is this `int` response a `string`?](./docs/http_int_response.md)
54+
<br />
55+
<br />
3556

36-
$ curl -X POST "localhost:8013/flags/isColorYellow/resolve/boolean" -d '{"color": "yellow"}'
37-
// {"value":true,"reason":"TARGETING_MATCH","variant":"on"}
57+
### Resolve a float value
58+
59+
Command:
60+
```sh
61+
curl -X POST "localhost:8013/flags/myFloatFlag/resolve/float"
62+
```
63+
Result:
64+
```sh
65+
{"value":1.23,"reason":"STATIC","variant":"one"}
66+
```
67+
<br />
68+
69+
### Resolve an object value
70+
71+
Command:
72+
```sh
73+
curl -X POST "localhost:8013/flags/myObjectFlag/resolve/object"
74+
```
75+
Result:
76+
```sh
77+
{"value":{"key":"val"},"reason":"STATIC","variant":"object1"}
78+
```
79+
<br />
3880

39-
$ curl -X POST "localhost:8013/flags/myBoolFlag/resolve/string"
40-
// {"error_code":"TYPE_MISMATCH","reason":"ERROR"}
81+
### Resolve a boolean value with evaluation context
4182

42-
$ curl -X POST "localhost:8013/flags/aMissingFlag/resolve/string"
43-
// {"error_code":"FLAG_NOT_FOUND","reason":"ERROR"}
83+
Command:
84+
```sh
85+
curl -X POST "localhost:8013/flags/isColorYellow/resolve/boolean" -d '{"color": "yellow"}'
4486
```
87+
Result:
88+
```sh
89+
{"value":true,"reason":"TARGETING_MATCH","variant":"on"}
90+
```
91+
<br />
92+
93+
### Return value type mismatch error
94+
95+
A type mismatch error is returned when the resolved value of a flag does not match the type requested. In the example below, the resolved value of `myBoolFlag` is a `boolean` but the request expects a `string` to be returned.
96+
97+
Command:
98+
```sh
99+
curl -X POST "localhost:8013/flags/myBoolFlag/resolve/string"
100+
```
101+
Result:
102+
```sh
103+
{"error_code":"TYPE_MISMATCH","reason":"ERROR"}
104+
```
105+
<br />
106+
107+
### Return flag not found error
108+
109+
The flag not found error is returned when flag key in the request doesn't match any configured flags.
110+
111+
Command:
112+
```sh
113+
curl -X POST "localhost:8013/flags/aMissingFlag/resolve/string"
114+
```
115+
Result:
116+
```sh
117+
{"error_code":"FLAG_NOT_FOUND","reason":"ERROR"}
118+
```
119+
45120

46121
### https
47122

docs/http_int_response.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# HTTP(S) Service Integer Response Behavior
2+
3+
4+
Why is my `int` response a `string`?
5+
Command:
6+
```sh
7+
curl -X POST "localhost:8013/flags/myIntFlag/resolve/int"
8+
```
9+
Result:
10+
```sh
11+
{"value":"1","reason":"STATIC","variant":"one"}
12+
```
13+
When interacting directly with the flagD http(s) api and requesting an `int` the response type will be a `string`. This behaviour is introduced by [grpc-gateway](https://github.com/grpc-ecosystem/grpc-gateway), which uses [proto3 json mapping](https://developers.google.com/protocol-buffers/docs/proto3#json) to build the response object. If a number value is required, and none of the provided SDK's can be used, then it is recommended to use the `float64` endpoint instead:
14+
<br />
15+
Command:
16+
```sh
17+
curl -X POST "localhost:8013/flags/myIntFlag/resolve/float"
18+
```
19+
Result:
20+
```sh
21+
{"value":1.23,"reason":"STATIC","variant":"one"}
22+
```

0 commit comments

Comments
 (0)