REST Web api application data managment

130 views Asked by At

I'm pretty confused about how should Manage the data in the RESTful web application I develop. How much of the data should be saved on client side?

For a more specific example:

My application sends letters from one system to another. I save the letters on server side using Sql server. For each letter there are destinations and the source represented by Address object containing full information about the the Addresses. I can't decide how should I manage the data of the Addresses in my application, should I:

  1. load all the Addresses to my client on start up and with each letter sendding stick the entire Addresses list to the reqeust? The request will contain more data and be bigger but I won't need to get all the stations on server

  2. load to client only the Id's of the addresses and send requests with Ids and then load them from a database on server side? Requests will contain smaller amount of data but I will need to fetch all Addresses on server

  3. Should I save on the client only the Address object representing his own Address and the other stations id's? Same as 2 but I won't need to fetch the Address of the sender

What are the pros/cons of each method? What would you choose in case the number of stations is around 100 (without so much data within each object)

I'm no professional so please correct me if anything I said was wrong/silly wording

Thanks in advance.

1

There are 1 answers

5
Sergii Apostol On BEST ANSWER

There is no silver bullet that works in all cases but i would suggest you to do it in next way:

  1. Load all addresses to client. Most probably end user prefer to see detailed address information instead of meaningless ids
  2. After user selected destination your app send only ids to server
  3. Server have to take address details by ids from db
  4. Send letter

Client should not send full address object as it might be (accidentally or by purpose) wrong.you should better always take real and valid data from DB. If you need to reduce load on DB you should better use server side caching. Example:

  1. Create repository that fetch addresses from db
  2. Create repository wrapper that take data from DB just once and then keep in MemoryCahce strucutre
  3. Use cached wrapper in you application