Skip to content
This repository has been archived by the owner on Jan 6, 2023. It is now read-only.

Commit

Permalink
Add docs about the endpoints (#22)
Browse files Browse the repository at this point in the history
  • Loading branch information
thomaspoignant authored Jun 13, 2022
1 parent 8ea925d commit 8b442e9
Show file tree
Hide file tree
Showing 7 changed files with 198 additions and 8 deletions.
1 change: 1 addition & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,6 @@ Resolve #
# Checklist
- [ ] I have tested this code
- [ ] I have added unit test to cover this code
- [ ] I have rebuilt the Swagger documentation (`make swagger`)
- [ ] I have updated the documentation (README.md)
- [ ] I have followed the [contributing guide](CONTRIBUTING.md)
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ The Relay Proxy defines many HTTP/HTTPS endpoints.
Most of these are proxies for GO Feature Flag services, to be used by SDKs that connect to the Relay Proxy.
Others are specific to the Relay Proxy, such as for monitoring its status.

Please refer to [endpoints documentation](docs/endpoints.md) to get the full details of what exists in our REST API.

## How can I contribute?
This project is open for contribution, see the [contributor's guide](CONTRIBUTING.md) for some helpful tips.
7 changes: 5 additions & 2 deletions controller/flag_eval.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,11 @@ func NewFlagEval(goFF *ffclient.GoFeatureFlag) Controller {
}

// Handler is the entry point for the flag eval endpoint
// @Summary allflags returns all the flag for a specific user.
// @Description allflags returns all the flag for a specific user.
// @Summary Evaluate the users with the corresponding flag and return the value for the user.
// @Description Evaluate the users with the corresponding flag and return the value for the user.
// @Description Note that you will always have a usable value in the response, you can use the field failed to know if
// @Description an issue has occurred during the validation of the flag, in that case the value returned will be the
// @Description default value.
// @Tags flags
// @Produce json
// @Accept json
Expand Down
4 changes: 2 additions & 2 deletions docs/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ const docTemplate = `{
},
"/v1/feature/{flag_key}/eval": {
"post": {
"description": "allflags returns all the flag for a specific user.",
"description": "Evaluate the users with the corresponding flag and return the value for the user.\nNote that you will always have a usable value in the response, you can use the field failed to know if\nan issue has occurred during the validation of the flag, in that case the value returned will be the\ndefault value.",
"consumes": [
"application/json"
],
Expand All @@ -121,7 +121,7 @@ const docTemplate = `{
"tags": [
"flags"
],
"summary": "allflags returns all the flag for a specific user.",
"summary": "Evaluate the users with the corresponding flag and return the value for the user.",
"parameters": [
{
"description": "Payload of the user we want to get all the flags from.",
Expand Down
180 changes: 180 additions & 0 deletions docs/endpoints.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,180 @@
# REST Endpoints

The most updated documentation about the relay proxy endpoints is the Swagger docs _(see [Swagger section](#swagger) to see how to access to the documentation)_.

## Specific to Relay Proxy

### Health (health check)
Making a `GET` request to the URL path `/health` will tell you if the **relay proxy** is ready to serve traffic.
This is useful especially for loadbalancer to know that they can send traffic to the service.

```json
{ "initialized": true }
```

### Info
Making a `GET` request to the URL path `/info` will tell give you information about the actual state of the **relay proxy**.
As of Today the level of information is small be we can improve this endpoint to returns more information.

```json
{
"cacheRefresh": "2022-06-13T11:22:55.941628+02:00"
}
```

| Field name | Type | Description |
|--------------------|------|-------------------------------------------------------------------------------------|
| `cacheRefresh` | date | This is the last time when your flag file was read and store in the internal cache. |


### Swagger
Swagger endpoint is serving a [swagger UI](https://swagger.io/tools/swagger-ui/) to test your REST endpoints.
By default, this endpoint is not exposed, you need to have this configuration in your **relay proxy** configuration file:

```yaml
# ...
enableSwagger: true
host: my-proxy-domain.com # the DNS to access the proxy
```
When enabled, you can go to the `/swagger/` endpoint with your browser, and you will have access to the Swagger UI for the relay proxy.

## Proxies for GO Feature Flag services

### Endpoint to get variation for a flag

Making a `POST` request to the URL `/v1/feature/<your_flag_name>/eval` will give you the value of the flag for this user.
To get a variation you should provide information about the user.
For that you should provide some user information in `JSON` in the request body.

#### Request
**Example:**
```json
{
"user": {
"key": "123e4567-e89b-12d3-a456-426614174000",
"anonymous": false,
"custom": {
"firstname": "John",
"lastname": "Doe",
"email": "john.doe@random.io"
}
},
"defaultValue": "default_value_provided_by_SDK"
}
```

| Field name | Type | Description |
|--------------------|--------------------|--------------------------------------------------------------------------------------------|
| `user` | [user](#user_type) | **(mandatory)** The representation of a user for your feature flag system. |
| `defaultValue` | any | **(mandatory)** The value will we use if we are not able to get the variation of the flag. |


#### Response

Based on the name of the flag and the user you will always have a response for the variation.
The API will respond with a `200` even if the flag is not available, the goal is for your application to not crash even if
the flag does not exist anymore.

**Example:**
```json
{
"value": "welcome_new_feature",
"variationType": "true",
"version": "0",
"trackEvents": true,
"failed": false
}
```

<a name="variation_results_details"></a>

| Field name | Type | Description |
|-----------------|---------|--------------------------------------------------------------------------------------------------------------------|
| `value` | any | The flag value for this user. |
| `variationType` | string | The variation used to give you this value. |
| `version` | string | The version of the flag used. |
| `trackEvents` | boolean | `true` if the event was tracked by the relay proxy. |
| `failed` | boolean | `true` if something went wrong in the relay proxy _(flag does not exists, ...)_ and we serve the **defaultValue**. |



### Endpoint to get all flags variations for a user

Making a `POST` request to the URL `/v1/allflags` will give you the values of all the flags for this user.
To get a variation you should provide information about the user.
For that you should provide some user information in `JSON` in the request body.

#### Request
**Example:**
```json
{
"user": {
"key": "123e4567-e89b-12d3-a456-426614174000",
"anonymous": false,
"custom": {
"firstname": "John",
"lastname": "Doe",
"email": "john.doe@random.io"
}
}
}
```

| Field name | Type | Description |
|--------------------|--------------------|--------------------------------------------------------------------------------------------|
| `user` | [user](#user_type) | **(mandatory)** The representation of a user for your feature flag system. |

#### Response

With the input user the API will loop over all flags and get values for all of them.

**Example:**
```json
{
"flags": {
"flag-only-for-admin": {
"value": false,
"timestamp": 1655123971,
"variationType": "Default",
"trackEvents": true
},
"new-admin-access": {
"value": false,
"timestamp": 1655123971,
"variationType": "False",
"trackEvents": true
}
},
"valid": true
}
```

| Field name | Type | Description |
|---------------|----------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------|
| `flags` | map[string]variationResult | All the flags with their results _(see [Endpoint to get all flags variations for a user](#variation_results_details) for the details of the format)_ |
| `valid` | boolean | `true` if something went wrong in the relay proxy _(flag does not exists, ...)_ and we serve the **defaultValue**. |

<a name="user_type"></a>
## User type

This type represent in your request body the information about a user.
This is based on these information that we will be able to filter which variation apply for this user.

```json
{
"key": "123e4567-e89b-12d3-a456-426614174000",
"anonymous": false,
"custom": {
"firstname": "John",
"lastname": "Doe",
"email": "john.doe@random.io"
}
}
```

| Field name | Type | Default | Description |
|-------------|------------------------|-----------|----------------------------------------------------------------------------------------------------------------------------------------|
| `key` | string | **none** | **(mandatory)** Unique key of your user, it could be any string, I recommend to use UUID, email or whatever who make your user unique. |
| `anonymous` | boolean | `false` | Is it an authenticated user or not. |
| `custom` | map[string]interface{} | **empty** | This is an object where you can put everything you think is useful, you will be able to use rule based on these fields. |
4 changes: 2 additions & 2 deletions docs/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@
},
"/v1/feature/{flag_key}/eval": {
"post": {
"description": "allflags returns all the flag for a specific user.",
"description": "Evaluate the users with the corresponding flag and return the value for the user.\nNote that you will always have a usable value in the response, you can use the field failed to know if\nan issue has occurred during the validation of the flag, in that case the value returned will be the\ndefault value.",
"consumes": [
"application/json"
],
Expand All @@ -112,7 +112,7 @@
"tags": [
"flags"
],
"summary": "allflags returns all the flag for a specific user.",
"summary": "Evaluate the users with the corresponding flag and return the value for the user.",
"parameters": [
{
"description": "Payload of the user we want to get all the flags from.",
Expand Down
9 changes: 7 additions & 2 deletions docs/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,11 @@ paths:
post:
consumes:
- application/json
description: allflags returns all the flag for a specific user.
description: |-
Evaluate the users with the corresponding flag and return the value for the user.
Note that you will always have a usable value in the response, you can use the field failed to know if
an issue has occurred during the validation of the flag, in that case the value returned will be the
default value.
parameters:
- description: Payload of the user we want to get all the flags from.
in: body
Expand Down Expand Up @@ -176,7 +180,8 @@ paths:
description: Internal server error
schema:
$ref: '#/definitions/echo.HTTPError'
summary: allflags returns all the flag for a specific user.
summary: Evaluate the users with the corresponding flag and return the value
for the user.
tags:
- flags
swagger: "2.0"

0 comments on commit 8b442e9

Please sign in to comment.