Friday, April 29, 2011

returning data efficiently

Like any good web framework, you can use the JSON format to send data to your application. The JSON data I was building in my layers controller was returning a 500 error, which was because the :include parameter is expecting attributes from multiple models, and fails if it doesn't find them. Once I removed :include, the JSON flowed freely.


You also want to make sure that you are using bandwidth efficiently. This means only returning the attributes that you need to use. To include specific attributes in your JSON return data, you can use the :only parameter to define only certain attributes to include in the data being sent. The callboxes model has 8 attributes; crime alerts has 13. By specifically transferring just the latitude and longitude, we reduce the size of the data by 81%.

No comments:

Post a Comment