NJTAPI is a Go library for accessing data about NJTransit Trains. It wraps the NJTransit HTTP API.
Features include:
- Timetables and statuses of departures from each station.
- Train status including location and stops.
- List of all the train stations in the system.
See the GoDoc for full details.
import "github.com/bamnet/njtapi"
Register with the NJTransit Developer Portal to get a username and password needed to call the API.
func main() {
username := "your username"
password := "your password"
client := NewClient("http://njttraindata_tst.njtransit.com:8090/njttraindata.asmx/", username, password)
station, err := client.StationData(context.Background(), "NY")
if err != nil {
log.Fatalf("StationData() error: %v", err)
}
fmt.Println("Departures from New York Penn Station")
for _, departures := range station.Departures {
fmt.Printf("Train to %s at %s", departures.Destination, departures.ScheduledDepartureDate)
}
}
Run demo.go for a working demo using a command like:
go run demo/demo.go --base_url="http://njttraindata_tst.njtransit.com:8090/njttraindata.asmx/" --username=<USERNAME> --password=<PASSWORD>
Note: Both of the samples above point to a testing api server, not the production one.