I am trying to add an external WFS as a datasource to my geoserver via REST API. I already added a new workspace and WFS datasource.

Now I want to publish a layer from that WFS on geoserver. The same works for WMS, but seems to be a bit different and poorly documented for WFS services.

I tried to request

PUT http://myhost.com/geoserver/rest/workspaces/my_workspace/datastores/my_datastore/layers

the following content as proposed in this post:

  <resource class="featureType">

This doesn't work out for me, I get a 500: Cannot cast org.geoserver.catalog.impl.LayerInfoImpl to org.geoserver.catalog.DataStoreInfo.

Now I am not sure, if it is required to create a FeatureType for the layer in advance. I added the layer manually via geoserver UI where it automatically detects the feature type from the WFS layer. I would like the same behaviour via the REST API.

Can anyone lead me towards the correct approach?


Maybe that will work, once I have created the featuretype. Just tried to get the featureType description from my manually created layer to adapt it. But there is a lot information I would have to put into the featuretype.xml manually just from the original WFS. I tried to insert the DescribeFeatureType output from the original WFS into this request:

POST /geoserver/rest/workspaces/my_workspace/datastores/my_datastore/featuretypes

But it complains about the syntax because the xsd:schema tags

<xsd:schema elementFormDefault="qualified" targetNamespace="http://..."><xsd:import namespace="http://www.opengis.net/gml" schemaLocation=".../schemas/gml/3.1.1/base/gml.xsd"/>

Not sure, if this is the expected FeatureType syntax?

  • Once you have created one using the GUI try doing a GET on it using REST this should show all the required information. The try modifying this template.
    – Ian Turton
    Commented Aug 25, 2015 at 14:50
  • Thanks for that hint. Just tried that and updated my question.
    – ulrich
    Commented Aug 25, 2015 at 15:10

2 Answers 2


Finally, iant's answer led me to the goal. For completeness I post what I have done:

After creating the datasource, main information on the WFS layers are known to geoserver. So I only had to do

POST /geoserver/rest/workspaces/my_workspace/datastores/my_datastore/featuretypes

with the name of the WFS layer, I wanted to publish


All additional information is created by geoserver itself, even the corresponding layer ist created automatically, so we are done at this point.

This was quite confusing to me, as the geoserver DescribeFeatureType output from the new layer found at


responds with an xsd-schema, which seems to be the expected output. But I also can request


which returns the featuretype description in xml format including additional information about the datasource.


You have to create a FeatureType before you can create a Layer (i.e. publish it). If you have already created a test layer then fetch the feature type of that one (like http://geoserver.ianturton.com/rest/workspaces/topp/datastores/bgs/featuretypes/test_uk_625k_mapped_feature.xml) but you should be able to delete quite a lot of that and leave it for GeoServer to fill in.

    <atom:link xmlns:atom="http://www.w3.org/2005/Atom" rel="alternate" href="http://geoserver.ianturton.com/rest/namespaces/topp.xml" type="application/xml"/>
  <description>net.opengis.wfs20.impl.AbstractTypeImpl@1f89241 (value: Just for testing, lang: &lt;unset&gt;)</description>
  <nativeCRS class="projected">PROJCS[&quot;OSGB 1936 / British National Grid&quot;, 
  GEOGCS[&quot;OSGB 1936&quot;, 
    DATUM[&quot;OSGB 1936&quot;, 
      SPHEROID[&quot;Airy 1830&quot;, 6377563.396, 299.3249646, AUTHORITY[&quot;EPSG&quot;,&quot;7001&quot;]], 
      TOWGS84[446.448, -125.157, 542.06, 0.15, 0.247, 0.842, -20.489], 
    PRIMEM[&quot;Greenwich&quot;, 0.0, AUTHORITY[&quot;EPSG&quot;,&quot;8901&quot;]], 
    UNIT[&quot;degree&quot;, 0.017453292519943295], 
    AXIS[&quot;Geodetic longitude&quot;, EAST], 
    AXIS[&quot;Geodetic latitude&quot;, NORTH], 
  PROJECTION[&quot;Transverse_Mercator&quot;, AUTHORITY[&quot;EPSG&quot;,&quot;9807&quot;]], 
  PARAMETER[&quot;central_meridian&quot;, -2.0], 
  PARAMETER[&quot;latitude_of_origin&quot;, 49.0], 
  PARAMETER[&quot;scale_factor&quot;, 0.9996012717], 
  PARAMETER[&quot;false_easting&quot;, 400000.0], 
  PARAMETER[&quot;false_northing&quot;, -100000.0], 
  UNIT[&quot;m&quot;, 1.0], 
  AXIS[&quot;Easting&quot;, EAST], 
  AXIS[&quot;Northing&quot;, NORTH], 
    <crs class="projected">EPSG:27700</crs>
    SPHEROID[&quot;WGS84&quot;, 6378137.0, 298.257223563]], 
  PRIMEM[&quot;Greenwich&quot;, 0.0], 
  UNIT[&quot;degree&quot;, 0.017453292519943295], 
  AXIS[&quot;Geodetic longitude&quot;, EAST], 
  AXIS[&quot;Geodetic latitude&quot;, NORTH]]</crs>
  <store class="dataStore">
    <atom:link xmlns:atom="http://www.w3.org/2005/Atom" rel="alternate" href="http://geoserver.ianturton.com/rest/workspaces/topp/datastores/bgs.xml" type="application/xml"/>

Experiment and when it works update the documentation for the next person along.

  • your link requires authentication. maybe you can post a part of the file structure.
    – ulrich
    Commented Aug 25, 2015 at 15:32
  • Thanks for this information, which was crucial to get the turn. Nevertheless, I posted as separate answer to explain my workflow.
    – ulrich
    Commented Aug 26, 2015 at 8:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.