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
andgeoserver
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);});
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.
Top comments (0)