Hiring Partners
Segilola Resources Operating LimitedTaviatech TechnologiesFCMBMTN NigeriaAdvans La Fayette Microfinance BankAboki AfricaFirst Bank of NigeriaOPay
โ† Certified GeoServer/KoboToolbox User Level Three ยท Lesson 7 of 12

Module Six

๐Ÿ“– Every lesson in this course is free to read right here, no account needed. Create a free account to track your progress, take the exam, and earn your certificate.
7
Module 6: GeoServer REST API & Automation
Level Three ยท Module 6

GeoServer REST API & Automation

Automate GeoServer administration programmatically with the REST API: manage workspaces, stores, layers, and styles, and integrate publication workflows into scripts and CI pipelines.

Duration: 5 hours Format: Theory + Hands-on Lab Prerequisites: Modules 1โ€“5

Module Overview

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.

Learning Objectives

  • Explain the design and resource model of the GeoServer REST API.
  • Authenticate REST requests securely and manage credentials.
  • Create, read, update, and delete workspaces, stores, layers, and styles via REST.
  • Automate layer publication workflows using scripts.
  • Integrate REST automation into CI/CD pipelines.
  • Troubleshoot common REST API errors and responses.

Topics Covered

6.1 REST API Fundamentals

  • Resource model and URIs
  • HTTP methods: GET, POST, PUT, DELETE
  • Content types: JSON and XML
  • Status codes and responses

6.2 Authentication

  • Basic authentication over HTTPS
  • Session cookies
  • Least-privilege service accounts
  • Credential management

6.3 Catalog Resources

  • Workspaces and namespaces
  • Stores (vector and raster)
  • Layers and resources
  • Layer groups

6.4 Styles & Publishing

  • Creating and uploading styles
  • Assigning default styles
  • Publishing layers programmatically
  • Versioning styles

6.5 Automation Workflows

  • Scripting with curl and Python
  • Idempotent publication scripts
  • Batch operations
  • Error handling and retries

6.6 CI/CD Integration

  • Pipelines for deployment
  • Configuration as code
  • Automated testing of services
  • Rollback strategies

Detailed Content

6.1 REST API Fundamentals

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.

  • GET: Retrieve a resource or list resources.
  • POST: Create a new resource.
  • PUT: Update an existing resource.
  • DELETE: Remove a resource.
# List all workspaces
GET /geoserver/rest/workspaces

# Create a new workspace
POST /geoserver/rest/workspaces
Content-Type: application/json
{ "workspace": { "name": "env-transport" } }
MethodPurposeTypical Response
GETRetrieve resources200 OK with resource body
POSTCreate resources201 Created
PUTUpdate resources200 OK or 204 No Content
DELETERemove resources200 OK or 204 No Content

6.2 Authentication

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: Send credentials in the Authorization header.
  • HTTPS: Always encrypt credentials in transit.
  • Service accounts: Use dedicated accounts with least privilege for automation.
  • Credential management: Store secrets in environment variables or secret managers.
# Basic authentication with curl
curl -u admin:secret \
  https://geoserver.example.org/geoserver/rest/workspaces
Warning Never hardcode credentials in scripts or commit them to version control. Use environment variables or a secrets manager.

6.3 Catalog Resources

The REST API exposes the full catalog: workspaces, namespaces, stores, layers, and layer groups. Understanding the resource hierarchy is essential for correct automation.

  • Workspaces: Create and manage logical containers.
  • Stores: Register data sources such as PostGIS or GeoTIFF.
  • Layers: Publish resources and assign styles.
  • Layer groups: Combine layers for single requests.
# 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" }
      ]
    }
  }
}

6.4 Styles & Publishing

Styles can be created and uploaded via REST, and assigned as default styles for layers. This enables fully automated publication workflows.

  • Create styles: Upload SLD or CSS content to a workspace.
  • Assign defaults: Set the default style for a published layer.
  • Publish layers: Register new layers from a store.
  • Version styles: Keep styles under version control alongside data.
# 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" } } }

6.5 Automation Workflows

Automation reduces manual effort and ensures consistency. Idempotent scripts check whether resources exist before creating them, enabling safe re-runs.

  • Scripting: Use curl, Python (requests), or other HTTP clients.
  • Idempotency: Check for existing resources before creation.
  • Batch operations: Loop over layers or files to publish at scale.
  • Error handling: Detect failures and retry or abort safely.
# 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}})
Best practice Write idempotent scripts that can be re-run without side effects. This makes deployments repeatable and safe.

6.6 CI/CD Integration

Integrating REST automation into CI/CD pipelines enables reproducible deployments and automated testing of geospatial services.

  • Pipelines: Use CI tools (GitHub Actions, GitLab CI) to run publication scripts.
  • Configuration as code: Store catalog configuration and styles in version control.
  • Automated testing: Validate GetCapabilities and GetMap responses after deployment.
  • Rollback: Keep previous configurations to restore on failure.
# Example CI step
- name: Publish layers
  run: |
    python scripts/publish_layers.py
  env:
    GS_USER: ${{ secrets.GS_USER }}
    GS_PASS: ${{ secrets.GS_PASS }}

Hands-On Lab: Automate Layer Publication via REST Scripts

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.

Lab Steps

  1. Write a script that lists all workspaces via REST and prints their names.
  2. Extend the script to create a workspace if it does not already exist (idempotent check).
  3. Register a PostGIS or GeoTIFF store in the workspace via REST.
  4. Publish a layer from the store and assign a default style.
  5. Upload an SLD or CSS style and verify it is applied to the layer.
  6. Add error handling that logs failures and exits with a non-zero status on error.
  7. Add a verification step that requests GetCapabilities and confirms the layer appears.
  8. Run the script twice to confirm idempotency and document the results.
Deliverable: A working Python script (or shell script) that automates workspace, store, layer, and style creation via the REST API, is idempotent, logs errors, and includes a verification step. Include a short report demonstrating two successful runs.

Suggested Session Timeline (5 Hours)

  • 0:00 โ€“ 0:45 โ€” REST API fundamentals and resource model
  • 0:45 โ€“ 1:30 โ€” Authentication and credential management
  • 1:30 โ€“ 2:15 โ€” Catalog resources via REST
  • 2:15 โ€“ 2:30 โ€” Break
  • 2:30 โ€“ 3:15 โ€” Styles and publishing automation
  • 3:15 โ€“ 3:45 โ€” CI/CD integration and testing
  • 3:45 โ€“ 4:45 โ€” Hands-on lab
  • 4:45 โ€“ 5:00 โ€” Review, Q&A, and lab debrief

Assessment

CriteriaWeight
Correct use of REST methods and resources20%
Authentication and credential management15%
Catalog resource creation via REST25%
Style upload and assignment15%
Idempotency, error handling, and verification25%

Pass mark for this module: 70%

Resources

  • GeoServer User Manual โ€” REST API reference
  • Python requests library documentation
  • curl documentation and examples
  • CI/CD tool documentation (GitHub Actions, GitLab CI)
  • Sample PostGIS and GeoTIFF datasets
© 2026 Certified GeoServer/KoboToolbox User โ€” Level Three ยท Module 6: GeoServer REST API & Automation

๐Ÿ† Get Certified

๐Ÿ”’

Earn this certificate

Every lesson is already free to read. Sign up, finish the lessons, pass the exam (โ‚ฆ2,000 or 20,000 coins), and get a verified certificate with your name on it.

๐ŸŽ“ Sign Up to Get Certified
๐Ÿ› ๏ธ Practice Tools
Hands-on simulators & labs - subscription required.
โ†’
๐ŸŽฏ Internship Tasks
Real-world tasks to build your portfolio - unlock them with a subscription.
โ†’