Chapter 6. Automating GeoServer Configurations

In this chapter, we will cover the following recipes:

  • Managing workspaces with REST
  • Creating and editing data stores with REST
  • Managing layers with REST
  • Uploading and updating styles with REST
  • Managing layers with the GWC REST API
  • Managing cache tiles with the GWC REST API

Introduction

So what is REST? The acronym stands for Representational State Transfer, which defines client-server interaction in terms of state transition. Each request from the client is a transition to a new state. The response sent by a server represents the application state after the transition.

Does it sound too complicated? If you are used to a stateful client server interaction, you will find REST unconventional. REST is stateless; once you get the general idea, you will discover it is very simple. A very important thing that you have to keep in mind is that each request is self-contained and you are never constrained to execute an operations chain or to open a session before making requests. That being said, it is always possible to create a complex workflow where several requests are chained to perform a task.

Note

Although REST is commonly considered as a web interface, it is much more. The term REST was defined by Roy T. Fielding, one of the main people behind HTTP protocol design, in his PhD thesis. REST describes how clients and servers interact and do it abstracting from any communication protocol. You could also develop a REST interface without HTTP.

You can read the original work of Roy T. Fielding at http://www.ics.uci.edu/~fielding/pubs/dissertation/top.htm.

A more lightweight approach on REST can be found at http://en.wikipedia.org/wiki/Representational_State_Transfer.

The GeoServer REST interface uses HTTP and defines a set of operations and resources. Operations are derived from HTTP so you can perform the GET, POST, PUT, and DELETE operations. Resources are the building blocks of GeoServer configuration: workspaces, data stores, layers, and so on.

Note

In the recipes of this chapter, we will use both cURL and Python to perform the same operations. Examples are showed in a Linux shell but cURL and Python syntax are identical in Windows shell.

REST defines a set of operations defined from the HTTP protocol, so how can you interact with it? Using a browser can be a common way to send HTTP requests to a server; you do it almost every day when you browse the Internet and you do it with the GeoServer web interface! However, using a browser is not a simple way to automate tasks; it requires human interaction. On the contrary, we need something that enables us to build small programs.

There are a lot of different tools that let you interact with REST. You can use programming languages such as Java or PHP or script languages such as PowerShell in Windows or any Linux shell. In this chapter, we will see examples in a programming language, Python, and with cURL. Python is a programming language that leverages on simplicity and code readability, and hence it is very easy to create small programs with it. cURL is a library and a command-line tool that can easily be incorporated in simple shell scripts. Both tools allow users to concentrate on what the program should do without being distracted by a complex syntax.

Note

In this chapter, it is assumed that you have a working installation of Python and cURL. If you are using a Linux box, it is quite probable you have both already installed and configured, or you can rely on your distribution package system to install a recent release.

For Windows, you can get Python from the project site at http://python.org/.

cURL is available as a source, for the brave, or as binary packages from http://curl.haxx.se/download.html.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.146.221.144