# Requests & responses

The conventions every endpoint shares: identifiers, filters, paging, field groups and units.

## Requests

The API is read only. Every endpoint is a `GET`, parameters go in the query string, and answers are JSON in UTF-8. Answers are compressed when you send `Accept-Encoding: gzip`, which most clients do by default.

## Identifiers

Every resource has two ways to name it:

| Field | Example | Use it for |
|---|---|---|
| `id` | `1375` | Storing a reference. It never changes. |
| `path` | `volkswagen/golf/viii-facelift-2024` | Display and URLs. It moves when something is renamed. |

[Lookup](https://autospec.launchit.ro/docs/lookup) turns a path back into resources.

## Filters

A filter is a field name, optionally followed by an operator:

```
power_kw.gte=150            at least 150 kW
year.between=2015,2020      in production at some point in those years
fuel=diesel,petrol          a comma means either
plug_in=true
```

Separate filters combine with **AND**. A comma inside one filter means **OR**. Numbers and dates take `.gt`, `.gte`, `.lt`, `.lte` and `.between=low,high`.

An unknown filter, an operator a field does not take, or a value outside a closed list is a `400` that names the problem. A filter is never quietly ignored, because that would answer a narrow question with the whole catalogue and look like a working request.

**400**

```json
{
  "detail": "fuel: 'coal' is not one of petrol, diesel, electricity, lpg, cng, ethanol_e85, ethanol_e100, hydrogen, synthetic_petrol. See /v1/vocabularies."
}
```

## Cars and motorcycles

The catalogue holds cars and motorcycles, and a model is one or the other. Every list answers with **cars** unless the request says otherwise:

```
vehicle_type=motorcycle        motorcycles only
vehicle_type=car,motorcycle    both
```

A motorcycle is chosen by its model and its year, so its tree is simpler than a car's: the model has one generation covering all the years it was built, and beneath it one version per model year, named after the year (`2019`, or `2015-2018` where the specification did not change). `body_type` holds its category: `scooter`, `naked`, `sport`, `enduro` and the rest of the [body vocabulary](https://autospec.launchit.ro/docs/vocabularies).

Models, generations and versions each carry a `vehicle_type` field. Fetching one record by id, and [resolving a path](https://autospec.launchit.ro/docs/lookup), work for either kind without the parameter.

Every list also takes `market` and `tier`, two facts about the make: `market=europe&tier.not=exotic,specialist` keeps to makes sold in Europe and leaves out hypercar and kit-car builders. See [makes](https://autospec.launchit.ro/docs/makes).

## Languages

`lang=de` on any request answers with names and labels in German, and likewise for the other [languages](https://autospec.launchit.ro/docs/languages). Left out, the answer is in English. Values, slugs and ids never change with the language.

## Paging

Lists return a page and a cursor:

**Response**

```json
{
  "items": [ ... ],
  "next_cursor": "WyJpZCIsMTM3NSwxMzc1XQ",
  "limit": 50
}
```

Pass `next_cursor` back as `cursor` to get the next page, and stop when it is `null`. Keep every other parameter the same while you page. `limit` sets the page size: 50 by default, 200 at most.

A cursor marks a position in a sort order, so a page far into the list costs the same as the first, and rows added while you page do not shift the ones you have yet to read.

## Sorting

`sort=name` sorts ascending, `sort=-name` descending. Each list documents the keys it accepts. Rows with no value for the sort key come last, in either direction.

## Empty values

A figure nobody published is `null`. It is never `0` and the field is never left out, so a client does not have to tell "missing" from "zero". A list with nothing in it is `[]`.

## Published records only

The API returns published records. A draft, or anything under an unpublished make, model or generation, does not appear in any list, cannot be fetched by id, and is not counted.

## Caching

Answers carry `Cache-Control: private`, because each one reports your account's balance in its headers. Cache them in your own application for as long as suits you: the catalogue changes rarely, and the [change feed](https://autospec.launchit.ro/docs/changes) tells you when it does.
