# Drivers

## Create a driver

<mark style="color:green;">`POST`</mark> `https://journal-de-bord-api.app/api/drivers`

Create a new driver. You need to create a new driver to create a new journal.

#### Headers

| Name          | Type   | Description                     |
| ------------- | ------ | ------------------------------- |
| Content-Type  | string | application/json                |
| Authorization | string | Bearer {Access token (J.W\.T.)} |

#### Request Body

| Name       | Type   | Description                                                                                       |
| ---------- | ------ | ------------------------------------------------------------------------------------------------- |
| identifier | string | This is a unique string. This should be the user identifier provided by the authorization server. |
| objective  | number | This is the number of kilometres the drivers wants to reach at the end of his training.           |

{% tabs %}
{% tab title="201 The driver was successfully created." %}

```
Empty body.
```

{% endtab %}

{% tab title="400 The request body was not valid or the authentication header was omitted." %}

```
{
    "timestamp": "2021-03-27T08:31:39.150+00:00",
    "status": 400,
    "error": "Bad Request",
    "message": "",
    "path": "/api/drivers"
}
```

{% endtab %}

{% tab title="409 Could not create a new driver because the authenticated user was already created." %}

```
{
    "timestamp": "2021-03-27T08:31:02.417+00:00",
    "status": 409,
    "error": "Conflict",
    "message": "",
    "path": "/api/drivers"
}
```

{% endtab %}

{% tab title="422 The identifier was specified in the request body but the logged user identifier does not match. This makes sure that the user can only create a driver for itself." %}

```
{
    "timestamp": "2021-03-27T08:32:04.883+00:00",
    "status": 422,
    "error": "Unprocessable Entity",
    "message": "",
    "path": "/api/drivers"
}
```

{% endtab %}
{% endtabs %}

## Get a driver

<mark style="color:blue;">`GET`</mark> `https://journal-de-bord-api.app/api/drivers/{identifier}`

This method is used to get the basic information of a driver.

#### Path Parameters

| Name       | Type   | Description                                                                                       |
| ---------- | ------ | ------------------------------------------------------------------------------------------------- |
| identifier | string | This is the identifier of the driver. The value should be set to the J.W\.T. subject (sub) field. |

#### Headers

| Name          | Type   | Description                     |
| ------------- | ------ | ------------------------------- |
| Authorization | string | Bearer {Access token (J.W\.T.)} |

{% tabs %}
{% tab title="200 The driver was found and is in the response body." %}

```
{
    "identifier": <driver's identifier>,
    "objective": <number of kilometers>
}
```

{% endtab %}

{% tab title="403 The logged user tries to access the driver resource of a different user." %}

```
{
    "timestamp": "2021-03-27T08:47:41.332+00:00",
    "status": 403,
    "error": "Forbidden",
    "message": "",
    "path": "/api/drivers/differentDriverIdentifier"
}
```

{% endtab %}

{% tab title="404 The driver does not exist and could not be found." %}

```
{
    "timestamp": "2021-03-27T08:47:41.332+00:00",
    "status": 403,
    "error": "Forbidden",
    "message": "",
    "path": "/api/drivers/unknownDriverIdentifier"
}
```

{% endtab %}
{% endtabs %}
