aboutsummaryrefslogtreecommitdiffstats
path: root/README.md
blob: cf6751c0aa79408fe9519d79de725040e2c98b6a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# atb

![Build Status](https://github.com/mpolden/atb/workflows/ci/badge.svg)

A minimal API for bus data in Trondheim, Norway. This API proxies requests to
Entur APIs and converts the responses into a sane JSON format.

Responses from the proxied APIs are cached. By default bus stops will be cached
for 1 week and departures for 1 minute.

As of mid-August 2021 the SOAP-based AtB API no longer returns any departure
data. According to [this blog post on open
data](https://beta.atb.no/blogg/apne-data-og-atb) it appears the preferred API
is now [Entur](https://developer.entur.org/). The `/api/v1/` paths have
therefore been removed.

Version 2 has been implemented and proxies requests to Entur instead. These are
the changes in version 2:

* There is no version 2 variant of `/api/v1/busstops`. Use
  https://stoppested.entur.org/ to find valid stop IDs.
* Entur uses different stop IDs so old ones, such as `16011376`, cannot be used
  in version 2. A stop includes departures in both directions by default so
  there is no longer a unique stop for each direction.
* The `registeredDepartureTime` field may be omitted.
* The `isGoingTowardsCentrum` field has moved to the departure object.

This API aims to be compatible with
[BusBuddy](https://github.com/norrs/busbuddy) (which appears to be defunct).

## Usage

```
$ atb -h
Usage of atb:
  -d string
    	Departure cache duration (default "1m")
  -l string
    	Listen address (default ":8080")
  -s string
    	Bus stop cache duration (default "168h")
  -x	Allow requests from other domains
```

## API

### `/`

Lists all available API routes.

Example:

```
$ curl https://mpolden.no/atb/ | jq .
{
  "urls": [
    "https://mpolden.no/atb/v2/departures"
  ]
}
```

### `/api/v2/departures`

List departures from the given bus stop, identified by a stop ID. Use
https://stoppested.entur.org to find stop IDs, for example `41613` (the number
part of `NSR:StopPlace:41613`) for Prinsens gate.

Departures traveling in any direction are included by default. Add the parameter
`direction=inbound` or `direction=outbound` to filter departures towards, or
away from, the city centre.

Note that the claimed direction is questionable in some cases so inspect the
responses to decide whether `inbound` or `outbound` makes sense for your use
case.

```
$ curl 'https://mpolden.no/atb/v2/departures/41613?direction=inbound' | jq .

{
  "url": "https://mpolden.no/atb/v2/departures/41613",
  "departures": [
    {
      "line": "71",
      "scheduledDepartureTime": "2021-08-11T23:49:38.000",
      "destination": "Dora",
      "isRealtimeData": true,
      "isGoingTowardsCentrum": true
    },
    ...
  ]
}
```