Using REST moduleΒΆ

This section contains a number of examples which illustrate various uses of the REST data configuration API.

The GeoServer REST configuration module uses the REST principles to expose services allowing to edit the catalog, in particular to manage workspaces, stores, layers, styles and groups.

The examples in this section use the cURL utility, which is a handy command line tool for executing HTTP requests and transferring files.

  1. Open the Terminal, execute curl_shell.bat located in the $geoserver_data (%geoserver_data% in Windows) directory and enter the following command:

    curl -u admin:Geos -v -XPOST -H "Content-type: text/xml" -d "<workspace><name>myworkspace</name></workspace>" http://localhost:8083/geoserver/rest/workspaces

the response should contains the following:


Create a new workspace via REST

  1. Go to the Workspaces section via Web interface to show the new workspace created


    Showing the new workspace created

  2. Get the new created workspace details entering the following:

    curl -u admin:Geos http://localhost:8083/geoserver/rest/workspaces/myworkspace.xml

    GET request to obtain new workspace details

  3. Publish a shapefile using the myworkspace workspace entering the following

    • Linux:

      curl -u admin:Geos -H "Content-type: application/zip" -T ${TRAINING_ROOT}/data/user_data/ http://localhost:8083/geoserver/rest/workspaces/myworkspace/datastores/pointlands/file.shp
    • Windows:

      curl -u admin:Geos -H "Content-type: application/zip" -T %TRAINING_ROOT%/data/user_data/ http://localhost:8083/geoserver/rest/workspaces/myworkspace/datastores/pointlands/file.shp
  4. Go to the Layer Preview to show the layers in a OpenLayers Map.


    Showing the new created layer


    The new created layers


    If you previously followed the security portion of the workshop the layer won’t be accessible because the administrator does not have the required roles. Go back in the service security section and remove the rule limiting the GetMap requests.

  5. Retrieves the created data store as XML entering the following:

    curl -u admin:Geos -XGET http://localhost:8083/geoserver/rest/workspaces/myworkspace/datastores/pointlands.xml
            <atom:link xmlns:atom="" rel="alternate" href="http://localhost:8083/geoserver/rest/workspaces/myworkspace.xml" type="application/xml"/>
            <entry key="url">file:${TRAINING_ROOT}/geoserver_data/data/myworkspace/pointlands/</entry>
            <entry key="namespace">http://myworkspace</entry>
            <atom:link xmlns:atom="" rel="alternate" href="http://localhost:8083/geoserver/rest/workspaces/myworkspace/datastores/pointlands/featuretypes.xml" type="application/xml"/>


    By default when a shapefile is uploaded a feature type resource and the associated layer are automatically created.

  6. Retrieve the layer as XML entering the following:

    curl -u admin:Geos -XGET http://localhost:8083/geoserver/rest/layers/myworkspace:pointlands.xml
            <atom:link xmlns:atom="" rel="alternate" href="http://localhost:8083/geoserver/rest/styles/point.xml" type="application/xml"/>
      <resource class="featureType">
            <atom:link xmlns:atom="" rel="alternate" href="http://localhost:8083/geoserver/rest/workspaces/myworkspace/datastores/pointlands/featuretypes/pointlands.xml" type="application/xml"/>


    When the layer is created a default style named point is assigned to it.

  7. Create a new style named landmarks with the following SLD (using the GeoServer Admin UI):

    <?xml version="1.0" encoding="ISO-8859-1"?>
    <StyledLayerDescriptor version="1.0.0"
     xsi:schemaLocation=" StyledLayerDescriptor.xsd"
      <!-- a Named Layer is the basic building block of an SLD document -->
            <!-- Styles can have names, titles and abstracts -->
              <Title>Default Point</Title>
              <Abstract>A sample style that draws a point</Abstract>
              <!-- FeatureTypeStyles describe how to render different features -->
              <!-- A FeatureTypeStyle for rendering points -->
                      <Title>Red Square</Title>
                      <Abstract>A 6 pixel square with a red fill and no stroke</Abstract>
                                        <CssParameter name="fill">#66FF66</CssParameter>
                                        <CssParameter name="stroke">#000000</CssParameter>
  8. Apply the existing landmarks style to the layer created myworkspace:pointlands (this operation does not overwrite the entire layer definition, updates it instead):

    curl -u admin:Geos -XPUT -H "Content-type: text/xml" -d "<layer><defaultStyle><name>landmarks</name></defaultStyle><enabled>true</enabled></layer>" http://localhost:8083/geoserver/rest/layers/myworkspace:pointlands
  9. Go to the Layer Preview to show the layers with the new landmarks style.


    Viewing the layers with the new created style landmarks