restxq response status

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

restxq response status

Pietro Liuzzo

Dear all,

I have a query like this in a restxq module. 

declare
%rest:GET
%rest:path("/BetMas/api/iiif/{$id}/manifest")
%output:method("json")
function iiif:manifest($id as xs:string*) {

(<rest:response>
            <http:response
                status="200">
                <http:header
                    name="Content-Type"
                    value="application/json; charset=utf-8"/>
                <http:header
                    name="Access-Control-Allow-Origin"
                    value="*"
                    />
            </http:response>
        </rest:response>,

map {"@context":= "http://iiif.io/api/presentation/2/context.json"}

  )
}
;

But I am not able to make it actually use that rest:response to add the http header Access-Control-Allow-Origin. Any hint on what I am doing wrong here?

Thank you very much!
Pietro

--
Pietro Maria Liuzzo
cel (DE): +49 (0) 176 61 000 606
Skype: pietro.liuzzo (Quingentole)


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Exist-open mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/exist-open
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: restxq response status

Adam Retter
Hi Pietro,

I am not sure which version of eXist you are using, but I just tested this with eXist-db 3.4.0. However the RESTXQ code has not changed for some time, so I would imagine anything back to 3.0.0 would give the same results.

I took your query and added the required namespaces and stored it as /db/test1.xqm:

xquery version "3.0";

module namespace iiif = "http://iiif";

declare namespace rest = "http://exquery.org/ns/restxq";
declare namespace http = "http://expath.org/ns/http-client";

declare 
    %rest:GET
    %rest:path("/BetMas/api/iiif/{$id}/manifest")
    %output:method("json")
function iiif:manifest($id as xs:string*) {

(<rest:response>
            <http:response
                status="200">
                <http:header
                    name="Content-Type"
                    value="application/json; charset=utf-8"/>
                <http:header
                    name="Access-Control-Allow-Origin"
                    value="*"
                    />
            </http:response>
        </rest:response>,
        


  )
};

It does seem to me that it correctly sets the HTTP Headers. I tested this using curl like so:

$ curl -v http://admin:@localhost:8080/exist/restxq/BetMas/api/iiif/12345/manifest

*   Trying ::1...
* TCP_NODELAY set
* Connected to localhost (::1) port 8080 (#0)
* Server auth using Basic with user 'admin'
> GET /exist/restxq/BetMas/api/iiif/12345/manifest HTTP/1.1
> Host: localhost:8080
> Authorization: Basic YWRtaW46
> User-Agent: curl/7.50.3
> Accept: */*
< HTTP/1.1 200 OK
< Date: Tue, 01 Aug 2017 15:22:49 GMT
< Set-Cookie: JSESSIONID=vhx0l86d9k4c1ikkphpoq3ns1;Path=/exist
< Expires: Thu, 01 Jan 1970 00:00:00 GMT
< Content-Type: application/json; charset=UTF-8
< Access-Control-Allow-Origin: *
< Vary: Accept-Encoding, User-Agent
< Transfer-Encoding: chunked
< Server: Jetty(9.3.9.v20160517)
{
* Curl_http_done: called premature == 0
* Connection #0 to host localhost left intact


So it looks to me that the header is set correctly in the response. Can you also test this? Perhaps you had the wrong namespace declared for the `http` prefix?

On 24 July 2017 at 08:00, Pietro Liuzzo <[hidden email]> wrote:

Dear all,

I have a query like this in a restxq module. 

declare
%rest:GET
%rest:path("/BetMas/api/iiif/{$id}/manifest")
%output:method("json")
function iiif:manifest($id as xs:string*) {

(<rest:response>
            <http:response
                status="200">
                <http:header
                    name="Content-Type"
                    value="application/json; charset=utf-8"/>
                <http:header
                    name="Access-Control-Allow-Origin"
                    value="*"
                    />
            </http:response>
        </rest:response>,

map {"@context":= "http://iiif.io/api/presentation/2/context.json"}

  )
}
;

But I am not able to make it actually use that rest:response to add the http header Access-Control-Allow-Origin. Any hint on what I am doing wrong here?

Thank you very much!
Pietro

--
Pietro Maria Liuzzo
cel (DE): +49 (0) 176 61 000 606
Skype: pietro.liuzzo (Quingentole)


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Exist-open mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/exist-open




--
Adam Retter

eXist Core Developer
{ United Kingdom / United States }
[hidden email]

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Exist-open mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/exist-open
Loading...