.. _gwc_rest_layers: Managing Layers =============== The GeoWebCache REST API provides a RESTful interface through which users can add, modify, or remove cached layers. .. note:: JSON is not recommended for managing layers as the JSON library has a number of issues with multi-valued properties such as "parameterFilters". Layer list ---------- URL: ``/gwc/rest/seed/layers.xml`` .. list-table:: :header-rows: 1 * - Method - Action - Return Code - Formats * - GET - Return the list of available layers - 200 - XML * - POST - - 400 - * - PUT - - 400 - * - DELETE - - 400 - The following example will request a full list of layers: .. code-block:: xml curl -u admin:geoserver "http://localhost:8080/geoserver/gwc/rest/layers" .. code-block:: xml img states raster test layer topp:states Layer Operations ---------------- URL: ``/gwc/rest/seed/layers/.xml`` .. note:: JSON is not recommended for managing layers as the JSON library has a number of issues with multi-valued properties such as "parameterFilters". .. list-table:: :header-rows: 1 * - Method - Action - Return Code - Formats * - GET - Return the XML representation of the layer - 200 - XML * - POST - Modify the definition/configuration of the layer - 200 - XML * - PUT - Add a new layer - 200 - XML * - DELETE - Delete the layer - 200 - .. note:: There are two different representations for cached layers, depending on whether the tile layer is created from the GeoServer WMS layer or layer group (``GeoServerLayer``), or is configured in ``geowebcache.xml`` as a regular GWC layer (``wmsLayer``). A GeoServer layer is referred to as a ``GeoServerLayer`` and contains no image data source information such as origin WMS URL. **Representations**: * GeoWebCache (``wmsLayer``) :download:`XML minimal ` * GeoWebCache (``wmsLayer``) :download:`XML ` * GeoServer (``GeoServerLayer``) :download:`XML minimal ` * GeoServer (``GeoServerLayer``) :download:`XML ` The examples below use the `cURL `_ tool, though the examples apply to any HTTP-capable tool or library. Adding a GeoWebCache layer ~~~~~~~~~~~~~~~~~~~~~~~~~~ The following example will add a new layer to GeoWebCache: .. code-block:: console curl -v -u admin:geoserver -XPUT -H "Content-type: text/xml" -d @layer.xml "http://localhost:8080/geoserver/gwc/rest/layers/newlayer.xml" The :file:`layer.xml` file is defined as the following: .. code-block:: xml newlayer image/png EPSG:900913 http://localhost:8080/geoserver/wms topp:states .. note:: The addressed resource (``newlayer`` in this example) must match the name of the layer in the XML representation. Adding a GeoServer layer ~~~~~~~~~~~~~~~~~~~~~~~~ The following example will add a new layer to both GeoServer and GeoWebCache: .. code-block:: console curl -v -u admin:geoserver -XPUT -H "Content-type: text/xml" -d @poi.xml "http://localhost:8080/geoserver/gwc/rest/layers/tiger:poi.xml" The :file:`poi.xml` file is defined as the following: .. code-block:: xml LayerInfoImpl--570ae188:124761b8d78:-7fd0 true tiger:poi image/png8 GoogleCRS84Quad 0 14 1 9 4 4 50 true .. note:: The addressed resource ( ``tiger:poi`` in this example) must match the name of the layer in the XML representation, as well as the name of an *existing* GeoServer layer or layer group. Modifying a layer ~~~~~~~~~~~~~~~~~ This example modifies the layer definition via the :file:`layer.xml` file. The request adds a parameter filter and a grid subset to the existing ``tiger:poi`` tile layer: .. code-block:: xml true tiger:poi image/png8 GoogleCRS84Quad 0 14 1 9 EPSG:900913 -8238959.403861314 4969300.121476209 -8237812.689219721 4971112.167757057 4 4 ELEVATION 0.0 0.0 1.0 2.0 3.0 4.0 1.0E-3 50 true Instead of PUT, use the HTTP POST method instead: .. code-block:: console curl -v -u admin:geoserver -XPOST -H "Content-type: text/xml" -d @poi.xml "http://localhost:8080/geoserver/gwc/rest/layers/tiger:poi.xml" Deleting a layer ~~~~~~~~~~~~~~~~ Deleting a GeoWebCache tile layer deletes the layer configuration *as well as the layer's disk cache*. No tile images will remain in the cache directory after deleting a tile layer. To delete a layer, use the HTTP DELETE method against the layer resource: .. code-block:: console curl -v -u admin:geoserver -XDELETE "http://localhost:8080/geoserver/gwc/rest/layers/newlayer.xml" .. note:: If trying to delete a tile layer that is an integrated ``GeoServerLayer``, only the GeoWebCache layer definition will be deleted; the GeoServer definition is left untouched. To delete a layer in GeoServer, use the GeoServer :ref:`rest` to manipulate GeoServer resources. On the other hand, deleting a GeoServer layer via the GeoServer REST API *will* automatically delete the associated tile layer.