Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
sebkur opened this issue Feb 1, 2019 · 6 comments
Open

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

sebkur opened this issue Feb 1, 2019 · 6 comments
Labels
question Further information is requested

Comments

@sebkur
Copy link

sebkur commented Feb 1, 2019

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...

@derhuerst derhuerst added the question Further information is requested label Feb 1, 2019
@derhuerst
Copy link
Owner

derhuerst commented Feb 1, 2019

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!

@sebkur
Copy link
Author

sebkur commented Feb 1, 2019

Thank you for the clarification

@derhuerst
Copy link
Owner

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

@sebkur
Copy link
Author

sebkur commented Feb 1, 2019

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 :)

@derhuerst
Copy link
Owner

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

@sebkur
Copy link
Author

sebkur commented Apr 9, 2019

Sounds good to me

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants