Skip to content

max results for /stations/:id/departures #3

Description

@sebkur

Is there a reason why the

GET /stations/:id/departures

endpoint does not support the results parameter to limit the number of results?

I'd find it quite useful to have this when I want to display just the next N trips at a station. Of course I can do it in the calling code, but still I think it would also make sense to have the classic parameter for limiting the number of results...

Activity

  1. derhuerst commented on Feb 1, 2019

    @derhuerst
    Owner

    Is there a reason why the departures endpoint does not support the results parameter to limit the number of results?

    Yes: The upstream API (HAFAS) only supports requesting by the period of time to return departures for. This correlates roughly with the number of returned departures, so you can query for e.g. 30 minutes and take the first 10 results.

    There's only one way for bvg-rest to guarantee a specific number of departures: Send multiple requests to HAFAS, collecting enough results. This can potentially take a significantly longer time, which is why it's currently not implemented. I would be a cool optional feature though!

  2. sebkur commented on Feb 1, 2019

    @sebkur
    Author

    Thank you for the clarification

  3. derhuerst commented on Feb 1, 2019

    @derhuerst
    Owner

    Do you think this is worth implementing in bvg-rest (or rather in the underlying hafas-rest-api)?

  4. sebkur commented on Feb 1, 2019

    @sebkur
    Author

    Well, I'm not sure. I thought about implementing the workaround with multiple requests myself in my user code. The funny thing is that I initially didn't think about the results parameter in the same way you do. I came to think about it because I actually got more results than expected, not fewer. My case should be easy to solve on the API end (although it is of course also easy to solve in my user code). Anyway, when the user code only needs N results max, we could easily support it and save some network traffic and save some processing on the user side. I was really thinking of the results parameter as an equivalent of limit in SQL, which also doesn't guarantee any minimum number of results, just that there won't be more than the specified limit. Maybe it would even be a good idea to call it that way, if it makes the meaning more clear. For example in the /stations/nearby case, with a very large value for results it will also not return as many results, say 1M :)

  5. derhuerst commented on Apr 8, 2019

    @derhuerst
    Owner

    We could name it e.g. maxResults. What do you think?

  6. sebkur commented on Apr 9, 2019

    @sebkur
    Author

    Sounds good to me

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions