leo0019 leo0019 - 20 days ago 5
JSON Question

looping through json from mysql or xcode

My app asks customers about features of the car they want to rent then it goes to my Database and do some search and come back with the findings and number of available cars based on the loop.

I'm just wondering which method is right to implement in my iOS app. In the API I created there is an

index
function to return all cars in my database in JSON style.

The question is: Should I create a function in my API that takes the parameters from app and loop in my database and return the result to customers?

or

Should the app get the index as JSON and do the loop with swift?

the JSON from the index will look something like this

[
{
"id": 1,
"created_at": "2016-11-13 12:06:02",
"updated_at": "2016-11-13 12:06:02",
"name": “R”,
"age": “12y”,
“plate#”: “43YTR”,
"status": "request",
"appearance": "ok",
“made”: “USA”
},
{
"id": 1,
"created_at": "2016-11-13 12:06:02",
"updated_at": "2016-11-13 12:06:02",
"name": “H_Y”,
"age": “4yt",
“plate#”: “11112JK”,
"status": “coming”,
"appearance": "ok",
“made”: “Korea”
},
]

Answer

Your question is:

Should I create a function in my API that takes the parameters from app and loop in my database and return the result to customers or should the app get the index as JSON and do the loop with swift?

There is no one answer to this as it depends on the expected size of the complete data set (JSON), the expected size of the result, the number of concurrent users, and how well your database is designed in terms of indexes.

If your JSON is relatively small, or the average result size will be a significant percentage of the whole dataset, then the second options seems fine. Once the overall data size becomes important while the result size is expected to be limited, it will become more beneficial to let the database do the work, and go for the first option.

This will lead to less client-server traffic, and also, database engines are generally good at responding to data queries with the use of indexes and caching mechanisms. It will be hard to beat that with the second option.

Comments