RESTFul Configuration API Use Cases
This documentation is no longer maintained. Please see the new GeoServer documentation at http://docs.geoserver.org
This page enumerates some simple configuration operations and how one would implement them. Examples are given in bash shell script (making heavy use of the curl utility) but of course porting to other languages should be straightforward. All examples assume a GeoServer instance running at http://example.com:8080/geoserver/
A quick curl refresher:
GET a web resource and print it to standard out:
$ curl http://example.com/
GET a web resource and save it to a file:
$ curl http://example.com/ \-o myfile.html
POST a form with fields 'foo', a string with value 'bar' and 'baz', a file upload from 'example.xml':
$ curl http://example.com/form \-F foo=bar,baz=@example.xml
PUT a file's contents:
$ curl http://example.com/myfile -T myfile
These examples are based on the proposed API, not the implemented one.
One-Step Shapefile Publishing
Assuming the shapefile and accompanying files are stored in ./myshapefile.zip:
$ curl -F typename=myshapefile,data=@myshapefile.zip, \ http://example.com:8080/geoserver/rest/datastores/mydatastore/featuretypes
Editing Metadata for a Featuretype
For a featuretype named "foo" in datastore "bar":
$ curl -o foo.xml http://example.com:8080/geoserver/rest/datastores/bar/featuretypes/foo.xml $ $EDITOR foo.xml $ curl -T foo.xml \ http://example.com:8080/geoserver/rest/datastores/bar/featuretypes/foo.xml
Autoconfigure Pre-loaded Data
To autoconfigure featuretypes that are loaded, but not configured, in datastore "foo":
$ curl -o featuretypes.xml \
http://example.com:8080/geoserver/rest/datastores/bar/featuretypes.xml
$ for LAYER in $(grep '<layer>' featuretypes.xml | sed 's/<.\?layer>//g');
do
curl -F typename=$LAYER \
http://example.com:8080/geoserver/rest/datastores/bar/featuretypes
done
Fetch and Configure Data from URL
For GeoServer to configure a coveragestore fetched from a remote server, http://example.com/mycoverage.tiff:
$ curl -F storename=$LAYER \ -F dataurl=http://example.com/mycoverage.tiff \ http://example.com:8080/geoserver/rest/coveragestores
Notes: We are autoconfiguring a coverage store here, not the actual coverage. Like the currently existing configuration app, we should detect when an autoconfigured datastore or coveragestore contains only a single layer and autoconfigure the layer as well.
Also, will the server be able to infer the type of the data, or do we need to add a form parameter for this as well?