PDA

View Full Version : REST API Problem



Sam Neuner
29-Apr-2020, 09:03 PM
Have a customer that we have developed a Restful API and a WebApp that communicates with this API. We have a non data-aware cWebList that makes a call to the API to fill the list. The user has a button to delete any selected row. It makes a call to the API to delete the record. This works fine. However, after the delete a Grid Refresh is sent to the List, but is still displays (API returns the data) the deleted record! Why? The same thing happens when the user creates a new record for the table and the List is re-displayed (again, a call to the API). Any ideas?

Mike Peat
30-Apr-2020, 03:19 AM
Sounds like a caching issue. Not quite sure what you should do about it - the service should be adding an HTTP Header "Cache-Control: no-cache", but it seems that perhaps it isn't (you could check that).

Mike

starzen
30-Apr-2020, 05:43 AM
first thing i would check is to make sure the API is really called. That would allow you to determine if there is any client side caching going on

you can try to send a Cache-Control header with value no-cache or no-store

https://developer.mozilla.org/en-US/docs/Web/HTTP/Caching

Sam Neuner
30-Apr-2020, 07:29 AM
Quite sure the API is really called because the List was initially filled with the correct data. What is the format for the no cache header, example? What would be the Header Name? I assume the Header Value would be "Cache-Constrol: no-cache"?

starzen
30-Apr-2020, 07:40 AM
Cache-Control: no-store


if the API is actually called you shouldnt have an issue with client side caching though. Have you debugged or logged the data being returned?

Sam Neuner
30-Apr-2020, 09:45 AM
When I execute the call from the browser it does not show that header when I view the "Headers" tab in the browser! Also, what would be the Header Name of the cache header?

starzen
30-Apr-2020, 10:06 AM
you need to add the header. the name is Cache-Control

Sam Neuner
30-Apr-2020, 10:15 AM
This is my header, it did not work:

Get AddHeader of oJsonHttp "Cache-Control" "Cache-Control: no-store" to bOk

starzen
30-Apr-2020, 10:28 AM
the header is for the server side

Sam Neuner
30-Apr-2020, 10:31 AM
I assume you mean in the Rest API? Where do I put that code?

Mike Peat
30-Apr-2020, 11:43 AM
Sam - are you writing the API (i.e. server-side) as well as the client? If so, what technology are you using?

Mike

Sam Neuner
30-Apr-2020, 11:45 AM
Yes, I am writing both using Dataflex.

Mike Peat
30-Apr-2020, 11:54 AM
Ah ha! 19.1 I presume, using the cWebHttpHandler? If so, use Send AddHttpResponseHeader "Cache-Control" "no-cache" (or "no-store" - both should work, IMO) before you return anything using the "OutputXXX" methods.

Mike

Sam Neuner
30-Apr-2020, 11:56 AM
Yes, using 19.1. I will give this a try. Thanks.

Sam Neuner
30-Apr-2020, 12:09 PM
Works great!!!! :) Thanks.