diff --git a/README.md b/README.md index 12e43a3..0576404 100644 --- a/README.md +++ b/README.md @@ -21,6 +21,56 @@ $ docker-compose up -d api ``` +### Usage + +#### API Key + +A ``master`` API key is created at the first launch of the application, API keys are stored in ``./api-keys.json`` file. + +An API key gives access to more fields returned by the API, for examples: + +```json +{ + "a7e666ed93d877d9a4f9": { + "name": "my-api-key", + "fields": { + "employees": ["*"], + "structures": ["field", "field.subfield", "field.*"], + } + }, + "939500eae15165ab4b8a": { + "name": "my-api-key", + "fields": { + "employees": ["field"], + } + }, + "e24d1167135d65bfcaad": { + "name": "my-api-key", + "fields": { + "structures": ["field.*"], + } + } +} +``` + +``employees`` *(type: Array)* and ``structures`` *(type: Array)* are optional, the fields returned by the API will be the default ones (cf: [Environment variables - **FIELDS_NAME**](#fieldsName)). + +The values of its tables can be: ++ ``*`` gives access to all the fields. ++ ``field`` gives access to a field ++ ``field.subfield`` gives access to a subfield ++ ``field.*`` gives access to all subfields + +There are two ways to use an api key, by the **header** ``x-api-key`` (in lowercase) or the **url parameter** ``apiKey``. + +Examples: + +```bash +$ curl -H "x-api-key: 6596ae25fdfdc83b85a7" http://localhost:3000/employees + +$ curl http://localhost:3000/employees?apiKey=6596ae25fdfdc83b85a7 +``` + ## Development ```bash @@ -40,15 +90,15 @@ | Name | Type | Description | | --- | --- | --- | -| APP_PORT | Integer | Application port ``(default: 3000)`` | -| ELASTICSEARCH_SCHEME | String | URI scheme ``(default: https)`` | -| ELASTICSEARCH_HOST | String | ElasticSerach host ``(default: localhost)`` | -| ELASTICSEARCH_PORT | Integer | ElasticSerach port ``(default: 9200)`` | -| ELASTICSEARCH_USERNAME | String | ElasticSerach host ``(default: elastic)`` | -| ELASTICSEARCH_PASSWORD | String | ElasticSerach host ``(default: changeme)`` | -| RESEDA_EMPLOYEES_INDEX | String | Reseda employees index name ``(default: employees)`` | -| RESEDA_STRUCTURES_INDEX | String | Reseda structures index name ``(default: structures)`` | -| PARAMS_MAX_SIZE | Integer | Query max size ``(default: 1000)`` | -| PARAMS_DEFAULT_SIZE | Integer | Query default size `` -(default: 25)`` | -| RESEDA_DOC_URL | String | OpenAPI URL ``(default: docs)`` | +| APP_PORT | Integer | Application port ``(default: 3000)`` | +| ELASTICSEARCH_SCHEME | String | URI scheme ``(default: https)`` | +| ELASTICSEARCH_HOST | String | ElasticSerach host ``(default: localhost)`` | +| ELASTICSEARCH_PORT | Integer | ElasticSerach port ``(default: 9200)`` | +| ELASTICSEARCH_USERNAME | String | ElasticSerach host ``(default: elastic)`` | +| ELASTICSEARCH_PASSWORD | String | ElasticSerach host ``(default: changeme)`` | +| RESEDA_EMPLOYEES_INDEX | String | Reseda employees index name ``(default: employees)`` | +| RESEDA_STRUCTURES_INDEX | String | Reseda structures index name ``(default: structures)`` | +| PARAMS_MAX_SIZE | Integer | Query max size ``(default: 1000)`` | +| PARAMS_DEFAULT_SIZE | Integer | Query default size ``(default: 25)`` | +| RESEDA_DOC_URL | String | OpenAPI URL ``(default: docs)`` | +| FIELDS_NAME | JSON | Default returned fields ``(default: { "employees": [ "nomUsage", "prenom", "UUIDPersonne", "affectationAdministrative.codeUnite" ], "structures": [ "codeUnite", "intituleUnite" ] })`` |