Automate GeoServer administration programmatically with the REST API: manage workspaces, stores, layers, and styles, and integrate publication workflows into scripts and CI pipelines.
Manual administration through the GeoServer web interface does not scale for enterprise deployments with many layers or frequent changes. The GeoServer REST API exposes the full catalog and security model over HTTP, enabling automation of routine tasks, reproducible deployments, and integration with CI/CD pipelines.
This module covers the REST API's design, authentication, and resource model. Learners will create, update, and delete workspaces, stores, layers, and styles programmatically, and build automation scripts that publish data consistently and reliably.
The GeoServer REST API follows RESTful conventions: resources are identified by URIs, and operations are expressed through HTTP methods. Most endpoints accept and return both JSON and XML.
# List all workspaces
GET /geoserver/rest/workspaces
# Create a new workspace
POST /geoserver/rest/workspaces
Content-Type: application/json
{ "workspace": { "name": "env-transport" } }
| Method | Purpose | Typical Response |
|---|---|---|
| GET | Retrieve resources | 200 OK with resource body |
| POST | Create resources | 201 Created |
| PUT | Update resources | 200 OK or 204 No Content |
| DELETE | Remove resources | 200 OK or 204 No Content |
REST requests must be authenticated when accessing protected resources. Basic authentication over HTTPS is common, though session cookies and other mechanisms are also supported.
# Basic authentication with curl
curl -u admin:secret \
https://geoserver.example.org/geoserver/rest/workspaces
The REST API exposes the full catalog: workspaces, namespaces, stores, layers, and layer groups. Understanding the resource hierarchy is essential for correct automation.
# Create a PostGIS store
POST /geoserver/rest/workspaces/env-utilities/datastores
Content-Type: application/json
{
"dataStore": {
"name": "utilities_pg",
"connectionParameters": {
"entry": [
{ "@key": "dbtype", "$": "postgis" },
{ "@key": "host", "$": "db.example.org" },
{ "@key": "database", "$": "utilities" },
{ "@key": "user", "$": "geoserver" },
{ "@key": "passwd", "$": "secret" }
]
}
}
}
Styles can be created and uploaded via REST, and assigned as default styles for layers. This enables fully automated publication workflows.
# Upload an SLD style
POST /geoserver/rest/workspaces/env-utilities/styles
Content-Type: application/json
{
"style": {
"name": "roads_sld",
"filename": "roads.sld",
"language": "SLD"
}
}
# Assign the style as default for a layer
PUT /geoserver/rest/workspaces/env-utilities/layers/roads
Content-Type: application/json
{ "layer": { "defaultStyle": { "name": "roads_sld" } } }
Automation reduces manual effort and ensures consistency. Idempotent scripts check whether resources exist before creating them, enabling safe re-runs.
# Example Python automation
import os, requests
base = "https://geoserver.example.org/geoserver/rest"
auth = (os.environ["GS_USER"], os.environ["GS_PASS"])
workspace = "env-utilities"
# Check if workspace exists
r = requests.get(f"{base}/workspaces/{workspace}", auth=auth)
if r.status_code == 404:
requests.post(f"{base}/workspaces", auth=auth,
json={"workspace": {"name": workspace}})
Integrating REST automation into CI/CD pipelines enables reproducible deployments and automated testing of geospatial services.
# Example CI step
- name: Publish layers
run: |
python scripts/publish_layers.py
env:
GS_USER: ${{ secrets.GS_USER }}
GS_PASS: ${{ secrets.GS_PASS }}
In this lab, you will build an idempotent Python script that automates the creation of a workspace, store, layer, and style, and verifies the published service.
| Criteria | Weight |
|---|---|
| Correct use of REST methods and resources | 20% |
| Authentication and credential management | 15% |
| Catalog resource creation via REST | 25% |
| Style upload and assignment | 15% |
| Idempotency, error handling, and verification | 25% |
Pass mark for this module: 70%