Sign up ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

As part of a possible solution to this question i want create a layer in GeoServer via REST that supplies a SQL statement along with a userid.

Reading I think i would create a feature type and publish it? I need to do this all in REST. Does anyone have any code examples?

share|improve this question
Is looks like it is not possible to add a layer via rest interface, did you resolve it in the end? I get the error: HTTP Status 405 - The specified HTTP method is not allowed for the requested resource –  a1an Jun 4 at 16:08

4 Answers 4

up vote 15 down vote accepted

There are many things you can do with the GeoServer REST API that are not specifically documented and that there are not code examples for. Here's the strategy for tackling those.

First, start with the examples in the documentation. Make sure you are familiar with how you can create a simple new layer or workspace using an HTTP POST with either XML or JSON.

Then, through the GeoServer UI, manually create the object you need for which there is no documentation (in this case, a feature type).

Finally, manually browse to the GeoServer REST index (http://your-server/rest or http://your-server/geoserver/rest). Browse through the index until you find the feature type you just created. Append ".xml" or ".json" to the URL of this resource, and you will see its XML or JSON representation.

This representation is what you would have needed to POST to create the feature type through the API. The URL of the representation is the URL that you would have needed to POST to (for example, http://your-server/geoserver/rest/..../myFeatureTypeName.json).

You can use this strategy to figure out how to programmatically create or configure any resource in GeoServer.

share|improve this answer
THANK YOU! Easy answer and just saved me another 2 hours of mocking around –  Ragi Yaser Burhum Mar 3 '12 at 0:24
In addition, a lot of the parameters can be skipped, and GeoServer will figure them out (just like in the UI). eg. bounding boxes –  rcoup Mar 7 '12 at 4:21

To add a layer, a datastore and a featuretype should be defined. Assuming they are already defined along with a style (as described in the guide at to add a layer a PUT request has to be sent to geoserver at:

With a data content like:

  <resource class="featureType">
share|improve this answer

If you understand Java you might want to take a look at this simple code that uses REST to do all kinds of operations on GeoServer.

share|improve this answer

Your best reference is in the user guide.

share|improve this answer
Yeah, but there is no example for creating a feature type from a SQL statement... i was hoping someone had example code to share. –  CaptDragon Aug 2 '11 at 14:56

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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