Go client for Washington DC Metro (WMATA) API
To install this package run:
go get -u github.com/awiede/wmata-go-sdk
In order to use the WMATA API, you will need to register with WMATA and get and API key. Information on how to get an API key can be found here.
This project is broken up into separate packages for each grouping of WMATA APIs (Please refer to these docs as the source of truth for all business rules)
The application is split up into the following services:
- wmata - Top level package. Houses
client
configuration to make API calls. (Note: This also houses the Misc Method API for health checks). - businfo - Service methods corresponding to Bus Route and Stop API.
- buspredictions - Service methods corresponding to Real-Time Bus Predictions API.
- incidents - Service methods corresponding to Indicents API.
- railinfo - Service methods corresponding to Rail Station Information API.
- railpredictions - Service methods corresponding to Real-Time Rail Predictions API.
- trainpositions - Service methods corresponding to Train Positions API.
All requests using this SDK are routed through a wmata.Client
. To create a client you will need an API key, and can optionally specify an http.Client
with all associated configurations.
apiKey := "<your-api-key>"
client := http.Client{
Timeout: time.Second * 60,
}
wmataClient := wmata.NewWMATAClient(apiKey, client)
// Defaults with a 30 second timeout
defaultClient := wmata.NewWMATADefaultClient(apiKey)
All services have a <package-name>.NewService
function which will build a new service. To create a service a wmata.Client
is required, as well as a choice of either communicating to WMATA via their JSON
or XML
endpoints.
// Create rail info service using WMATA client in previous example
railInfoService := railinfo.NewService(wmataClient, wmata.JSON)
// Invoke the GetLines() method of the rail service to get active line info
activeRailLines, err := railInfoService.GetLines()