OGC-IoT / ogc-iot-api

http://ogc-iot.github.io/ogc-iot-api/index.html
11 stars 3 forks source link

HTTP Response Header does not include Last-Modified #29

Open b-en opened 10 years ago

b-en commented 10 years ago

I am trying to load observations from a datastream only in the event that there is a new observation. I think the easiest way to do this would be an ajax call that is executed if there has been a change since 'Last-Modified'. jQuery has built in functionality to keep track of this using an ajax call with 'ifModified'. I have implemented the following to test:

$('#getButton').click(function () {
    $.ajax({
        type: "GET",
        url: 'http://demo.student.geocens.ca:8080/SensorThings_V1.0/Things(1)/',
        dataType: 'json',
        cache: true,
        ifModified: true,

        success: function (data, textStatus, jqXHR) {
            // Always returns 200:success, never 304
            console.log(jqXHR.status + ':' + textStatus);
            console.log(data);

            // The following returns null
            console.log(jqXHR.getResponseHeader("Last-Modified"));
        },
        complete: function (jqXHR, textStatus) {
            if (jqXHR.status != 200) {
                console.log(jqXHR.status + ':' + textStatus);
            }
        }
    });
});

http://jsfiddle.net/Lxum7/2/

I understand that there are some limitations on how jQuery handles 304s but I think this case should work. The problem is that I am always given a 200 response and the data is sent. Is the intended behavior? I believe that it is doing this because the HTTP response header does not send the Last-Modified date.

I think another way to possibly accomplish what I want to do would be to utilize $skip, which I will look into if this is working as intended.

alec192huang commented 10 years ago

Hi Ben,

Sorry for the late reply and thank you for your comment. After some discussion, we are planning to put Last-Modified as mandatory in the spec. We will update the SensorThings API website ASAP.

And actually, in the current SensorThings spec, there is another way to fulfill your use case, which is by using the $filter option. For example, if a user wants to get new observations of the Datastream(1) and the last observation the user has retrieved was at 2012-05-29T00:02:15-0600, the user can send the following request to get all the observations of Datastream(1) that happened after 2012-05-29T00:02:15-0600.

http://demo.student.geocens.ca:8080/SensorThings_V1.0/Datastream(1)/Observations?$filter=Time gt '2012-05-29T00:02:15-0600'

However, it seems that the current service implementation has some issues with this request. And we are actively looking into the issue.

Alec