Transit Index API: All routes from an agency

338 views
Skip to first unread message

Aitzol

unread,
Jan 16, 2016, 12:58:45 PM1/16/16
to OpenTripPlanner Developers
Hi,

I am trying to list all routes from an Agency by using Transit Index API. This seems to be harder that I though, because I expected to be an enpoint such as /index/routes/{AgencyId} to list me all the routes operated by an agency.

However, after reviewing https://groups.google.com/d/msg/opentripplanner-dev/rylPh3hYggk/xr3llzWuf9wJ and https://github.com/opentripplanner/OpenTripPlanner/blob/1320_patterns/otp-core/src/main/java/org/opentripplanner/index/IndexAPI.java I think that it is not the case.

There are the following endpoints about routes:
  • /otp/routers/default/index/routes/: Returns data about all routes operated by all agencies in the graph
  • /otp/routers/default/index/routes/{id}: Returns data about a route, given its route ID.

I would need something in the middle of the examples above: an endpoint that returns the data of all routes operated by a agency (not all agencies in the graph). How can I get this data?


Thanks,

Aitzol

Tuukka Hastrup

unread,
Jan 28, 2016, 11:39:54 PM1/28/16
to Aitzol, OpenTripPlanner Developers
Hi,

similar here as I just wrote on opentripplanner-users:
> one very flexible and efficient option would be to use API from the
> branch "Implement the index API on top of GraphQL" available here:
> https://github.com/opentripplanner/OpenTripPlanner/pull/2032

Here's your query in GraphQL:

{agency(id:"HSL") {routes {gtfsId type shortName longName}}}

You could choose to select any other properties and subproperties you
wanted instead of or in addition to just getting routes and their id,
type and names.

> Example code in Python:
>
https://github.com/karrika/RPi-InfoScreen-Kivy/blob/Helsinkibus/screens/finlandarrivals/finlandarrivals.py

> GraphQL API console for testing these queries with data for Finland:
> http://dev.hsl.fi/graphql/console/

> General introduction to GraphQL queries:
> http://graphql.org/docs/queries/

-Tuukka

2016-01-16, 19:58, Aitzol kirjoitti:
> Hi,
>
> I am trying to list all routes from an Agency by using Transit Index
> API. This seems to be harder that I though, because I expected to be an
> enpoint such as /index/routes/{AgencyId} to list me all the routes
> operated by an agency.
>
> However, after reviewing
> https://groups.google.com/d/msg/opentripplanner-dev/rylPh3hYggk/xr3llzWuf9wJ
> and
> https://github.com/opentripplanner/OpenTripPlanner/blob/1320_patterns/otp-core/src/main/java/org/opentripplanner/index/IndexAPI.java
> I think that it is not the case.
>
> There are the following endpoints about routes:
>
> * /otp/routers/default/index/routes/: Returns data about all routes
> operated by all agencies in the graph
> * /otp/routers/default/index/routes/{id}: Returns data about a route,

Andrew Byrd

unread,
Jan 29, 2016, 4:43:12 AM1/29/16
to Aitzol, OpenTripPlanner Developers
Hello Aitzol,

The index API tries to use uniformly hierarchical URLs that resemble a filesystem. You suggest that the information you need should be provided at the URL "/index/routes/{AgencyId}” but a URL pattern of that form already exists. It matches “/index/routes/{routeId}”. It selects a particular route by ID (it looks in the routes directory for a particular routeId).

What you want to do is select a particular agency and list all the routes in that agency, which you’d do with "/agencies/{agencyId}/routes”, i.e. out of the directory of agencies select agencyId, then show the directory of routes within that agencyId.


Looking at this file now, I see that in the particular case you’re interested in a feedId has been inserted into the URL pattern giving  "/agencies/{feedId}/{agencyId}/routes". It makes perfect sense to specify a feedId, but I’m not sure why only the agency-related endpoints have one, nor why it’s at this position in the URL (hierarchically underneath the agency rather than at the root). This makes the API less uniform and non-intuitive. I’ll check with the author of this commit about revising it.

I would expect the feed ID would be specified using the feedId:entityId syntax or placed at the root of the URL hierarchy, but the more types of information we allow retrieving and the more types of information we allow when selecting entities, the less obvious it is how to lay out this hierarchy. 

Tuukka is right, GraphQL is really the right answer to the index API. It just gets rid of all these concerns. We should switch over to GraphQL and keep the current index API only for backward compatibility. I’ll try to get that pull request merged today.

Andrew

  • /otp/routers/default/index/routes/: Returns data about all routes operated by all agencies in the graph
  • /otp/routers/default/index/routes/{id}: Returns data about a route, given its route ID.

I would need something in the middle of the examples above: an endpoint that returns the data of all routes operated by a agency (not all agencies in the graph). How can I get this data?


Thanks,

Aitzol

--
You received this message because you are subscribed to the Google Groups "OpenTripPlanner Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to opentripplanner...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Aitzol

unread,
Jan 31, 2016, 4:31:52 PM1/31/16
to OpenTripPlanner Developers, aitzo...@gmail.com
Hi Tuukka and Andrew,

Thanks a lot for your comprehensive explanation.

I will have a look to the documentation about GraphQL and discard the use of the index API.

Kind regards,

Aitzol
Reply all
Reply to author
Forward
0 new messages