1

I need to delete a Datastore (as well as all its content) using GeoServer's REST API.

I'm trying:

curl -u usr:pwd -XDELETE http://example.com/geoserver/rest/workspaces/ws/datastores/my_datastore.xml

But the response I get is:

datastore not empty

So, I assume I need to delete all layers in My Datastore. Fine.

Deleting all layers in the datastore:

I couldn't find a way to list only the layers in a concrete DS, so I did:

curl -u usr:pwd -XGET http://example.com/geoserver/rest/layers.json

that returns something like:

{
    "layers":{
        "layer":[
            ..., // Some unrelated layers
            {
                "name":"my_datastore.poi",
                "href":"http://example.com/geoserver/layers/my_datastore.poi.json"
            },
            {
                "name":"my_datastore.sector",
                "href":"http://example.com/geoserver/layers/my_datastore.sector.json"
            },
            ... // More unrelated layers
        ]
    }
}

After filtering this response to get only the layers in the datastore to be deleted, I delete every layer doing:

curl -u usr:pwd -XDELETE http://example.com/geoserver/layers/my_datastore.poi.json
curl -u usr:pwd -XDELETE http://example.com/geoserver/layers/my_datastore.sector.json

And it apparently works (if I check in the GeoServer's web interface, the layers are gone...)

Finally, deleting the supposedly empty datastore

After deleting the layers I try again:

curl -u usr:pwd -XDELETE http://example.com/geoserver/rest/workspaces/ws/datastores/my_datastore.xml

But:

datastore not empty

So, my double question is:

  1. What else do I need to delete for the datastore to be empty?
  2. Is there any easier way to delete a Datastore (and its content) via REST API?
2

You need the recurse parameter set to true. GeoServer will then delete all the layers in the datastore.

  • Thank you very much, Ian. Even though you linked to workspace's recurse, now I've seen that there is a recurse option for datastores too. Your answer is exactly what I was looking for but it only answers my question #2. Just for the sake of learning, do you know the answer to #1 also? Thanks again. – Jordi Nebot Jan 2 '18 at 18:53
  • whoops, I've fixed the link now, copy paste is hard to check on my phone. As for #1 all I can suggest is looking at the code (github.com/geoserver/geoserver/blob/master/src/restconfig/src/…) to see what it does with recurse – Ian Turton Jan 3 '18 at 8:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.