Answer the question
In order to leave comments, you need to log in
How to implement a request to rest?
I am writing a small simple REST service, from which the desktop interface receives data.
It takes some data in the database on request and returns them in json
. The question arose how to correctly implement the selection of information for a certain period?
There are 2 options - one is mine, the second one was offered to me.
My option is to set the period, for example, from 1 to 10, the desktop interface itself will in turn request data for 1, 2, 3, and so on numbers and then display the information.
Of the minuses - having a period of a thousand days, there will be 1000 requests to select each record.
But the API has a simple form: service.address/statistic/{date}
And the second option - we send the start date, end date and page number to the service
Dates - in order to indicate the period for which we will sample the data and the page number to "split" the transmitted data in order to save traffic and download data in portions.
At the same time, since the Rest service cannot save state between requests, when fetching each page, we will have to select data for the entire period, split it into pages (for example, 1000 records, divide by 100 and return them. Total 10 requests to the database per sample 1000 records) and give part of the data from the page number
Total we get
service.address/statistic/{beg_date}/{end_date}/ - returns the number of pages
service.address/statistic/{beg_date}/{end_date}/{page_num} - returns data packet.
And so ... What is more correct?
Or maybe there is a third more correct option?
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question