1

I have a table(named sample) having some 100+ records and how can I write an api such that I want to fetch 'n' no of records as per index passed returning in json format,

for eg: if index=0 is passed i want to show first 0-5 records and for index=1 i want to show 6-10 records and so on.....

I have no idea to approach, but i am trying to fetch the index no. of records:

@app.route("/rows/<index>",methods=['GET'])
def getrecords():
    records=sample.query.filter()[:index] # which would return top index no of records 

got mute on how to fetch records based on index(as explained above )....any help is appreciated!!

I am looking for something like, if <index>=0 is passed then return a json of 0 to 5 records and if <index>=5 is passed then return a json of 6 to 10 and so on.....

This is actually asked for pagination ,but i need to see whether it works with (POSTMAN)

KcH
  • 3,302
  • 3
  • 21
  • 46
  • @AndrewAllen This is different from what i asked mate, it's true i am using this for pagination , but i reffered that answer no clue yet – KcH Sep 27 '19 at 12:26
  • The redirected answer doesn't give exact solution , How can i just check through postman if it works!!.......?? – KcH Sep 28 '19 at 05:51
  • I personally use [marshallow-SQLAlchemy](https://marshmallow-sqlalchemy.readthedocs.io/en/latest/) to convert to json and return `jsonify(data), status_code` where status_code is say 200 or 201 – Andrew Allen Sep 28 '19 at 06:32
  • yeah i knew this, but how I am thoughtless on how to achieve that index thing mentioned in question....any idea? – KcH Sep 28 '19 at 06:57
  • `@app.route('/rows/') def page(index): record_query = sample.query.paginate(index, 5, False) record_items = record_query.items return `yourschema`.jsonify(record_items)`....................If someone looking for answer!! – KcH Sep 29 '19 at 14:15

0 Answers0