[GIS] Difference between outcome of REST query through browser and through cURL

curlgeoservergeoserver-rest-api

I am working with the geoserver rest interface to automate the config of all layers, stores etc.
One thing I noticed was that when using a browser and navigating to a layer the outcome is something like the information below:

Sample url: http://SomeServer/geoserver/rest/layers/SomeLayer.html

Layer "SomeLayer"

    Name: SomeLayer
    Default style: StyleInfoImpl[layerStyle]
    Available styles: []

When using the same url but through cURL I get:

curl -v -u user:password -XGET http://SomeServer/geoserver/rest/layers/SomeLayer -H "accept: application/xml" -H "content-type: application/json"

<layer>
  <name>SomeLayer</name>
   <type>VECTOR</type>
  <defaultStyle>
    <name>LAyerStyle</name>
  </defaultStyle>
  <resource class="featureType">
    <name>SomeLayer</name>
  </resource>
  <enabled>true</enabled>
  <queryable>true</queryable>
  <metadata>
    <entry key="GWC.autoCacheStyles">true</entry>
    <entry key="GWC.metaTilingX">4</entry>
    <entry key="GWC.metaTilingY">4</entry>
    <entry key="GWC.gutter">0</entry>
    <entry key="advertised">true</entry>
    <entry key="GWC.enabled">true</entry>
    <entry key="GWC.cacheFormats">image/png,image/jpeg</entry>
    <entry key="GWC.gridSets">EPSG:4326,EPSG:900913</entry>
  </metadata>
  <attribution>
    <title>Bla</title>
    <href>https://www.some-url.org</href>
    <logoWidth>0</logoWidth>
    <logoHeight>0</logoHeight>
  </attribution>
</layer>

When using cURL I get much more attributes such as "enabled", "Queryable" and "Metadata".

Is this normal behaviour, am I missing something when navigating to the layer information in a browser?
I am using geoserver 2.12, but I have noticed this behavior already in 2.1.

Best Answer

Actually, this has nothing to do with the way you make the request. RESTful services can provide different representations of their state depending on the output format you request. So the information you get back is the same in the browser and the command line if you go to a URL like:

http://localhost:8080/geoserver/rest/layers/topp:states.xml 

in the browser or using CURL (or you can drop the .xml in CURL and add -H "accept: application/xml"). If however, you go to

http://localhost:8080/geoserver/rest/layers/topp:states.html

You will get the HTML representation back, this has less information in it as it's designed for humans not machines. In this case, you will see the HTML by default in the web browser if you don't specify the extension as that is what browsers expect to get.

Related Question