What is the correct endpoint in the latest production version of GeoServer to create a layer in a datastore (I’m using PostGIS)?
https://docs.geoserver.org/latest/en/api/#1.0.0/datastores.yaml the same as in every other version
Ian
I’m new to Geoserver and I’m a bit confused. I want to create a layer, but when I look at the store named ‘datastore’, it seems that the layer is referred to as ‘featuretype’. Does ‘FeatureType’ in Geoserver refer to a layer?
I would recommend getting familiar with GeoServer using the GUI before you try to make use of the REST API but there is infact an example of exactly what you are trying to do on the page I linked to.
So you need to put a json file like:
{
"dataStore": {
"name": "nyc",
"connectionParameters": {
"entry": [
{"@key":"host","$":"localhost"},
{"@key":"port","$":"5432"},
{"@key":"database","$":"nyc"},
{"@key":"user","$":"bob"},
{"@key":"passwd","$":"postgres"},
{"@key":"dbtype","$":"postgis"}
]
}
}
}
to the /workspaces/{workspaceName}/datastore endpoint of your server.
Then you will be able to create layers from the tables in that schema (or public) if you don't specify it.
Ian
Thank you for your advices but I’ve already created my datastore using the interface. I also created a layer (or feature type?) via the REST API (see below with example of .http file).
What I don’t understand is why it’s referred to as a feature type in the case of a datastore. I retrieve this feature type from the layers panel in the GUI.
POST http://localhost:8080/geoserver/rest/workspaces/nyc/datastores/nyc_buildings/featuretypes
Content-Type: application/xml
Authorization: Basic YWRtaW46Z2Vvc2VydmVy
<featureType>
<name>my_new_featuretype</name>
<nativeName>nyc_buildings</nativeName>
<!-- The name of the table in PostGIS -->
<title>My New FeatureType</title>
<srs>EPSG:4326</srs>
<!-- Coordinate reference system, change if necessary -->
<enabled>true</enabled>
<!-- This makes the feature type enabled -->
</featureType>