DEV Community

Cover image for Update/Publish Styles on GeoServer from Javascript using REST
Ibrahim Awad
Ibrahim Awad

Posted on • Edited on

4

Update/Publish Styles on GeoServer from Javascript using REST

Hi there!
Do you want to publish or update some styles on GeoServer, that's easy, check out the official documentation for that. After you read it and can't use it in your javascript code, come here, this post will help you.

I'll skip the unnecessary chat about various situations you might need this and get right to it.
I'm using axios to handle my connections (because I like it :D), but you can do it with other libraries or even with vanilla JS.

Update an existing style (using PUT)

  • First prepare the StyleContent which is the content of the style file as if you normally would upload it through geoserver interface.
  • Make sure you have the right access, I'm using default username and password for geoserver admin and geoserver for this.
const geoserverURL = 'http://{GEOSERVER_HOST}/geoserver/rest/workspaces/{WORKSPACE}/styles/{STYLE_NAME}'
axios({
    method: 'put',
    url: geoserverURL,
    data: StyleContent,
    auth: {
        username: 'admin',
        password: 'geoserver'
    },
    headers: {'Content-Type': 'application/vnd.ogc.se+xml'}
}).then((response) => {}, (error) => {console.log(error);});
Enter fullscreen mode Exit fullscreen mode

Publish a new style

Guess what happens if you change the method from put to post from the previous code? That's correct! you publish a new style to geoserver.

SurveyJS custom survey software

Simplify data collection in your JS app with a fully integrated form management platform. Includes support for custom question types, skip logic, integrated CCS editor, PDF export, real-time analytics & more. Integrates with any backend system, giving you full control over your data and no user limits.

Learn more

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs