Create database postgis from API REST datastores.yml

When using the GeoServer GUI (DataAccessNewPage), the database is created successfully when I add the following parameters:

In debug mode within my GeoServer source code, I noticed that DataStoreUtils is responsible for creating the database via the call ‘factory.createDataStore(params);’. In this case, the factory used is PostgisNGDataStoreFactory.

However, when using the REST API (DataStoreController#dataStorePost(…)), the database does not appear to be created. This is because ‘factory.createDataStore(params);’ is never called.

Here’s an example of the POST request I am sending:

Example of POST:

post datastore

curl -X POST “http://localhost:8080/geoserver/rest/workspaces/myworkspace/datastores
-H “Content-Type: application/json”
-H “Authorization: Basic YWRtaW46Z2Vvc2VydmVy”
-d ‘{
“dataStore”: {
“name”: “myStore”,
“connectionParameters”: {
“entry”: [
{“@key”:“host”,“$”:“localhost”},
{“@key”:“port”,“$”:“5432”},
{“@key”:“database”,“$”:“mybdd”},
{“@key”:“user”,“$”:“gis”},
{“@key”:“passwd”,“$”:“password”},
{“@key”:“dbtype”,“$”:“postgis”},
{“@key”:“Connection timeout”,“$”:“20”},
{“@key”:“validate connections”,“$”:“true”},
{“@key”:“Support on the fly geometry simplification”,“$”:“true”},
{“@key”:“create database”,“$”:“true”},
{“@key”:“Batch insert size”,“$”:“1”},
{“@key”:“Max connection idle time”,“$”:“300”},
{“@key”:“Expose primary keys”,“$”:“false”},
{“@key”:“min connections”,“$”:“1”},
{“@key”:“Max open prepared statements”,“$”:“50”},
{“@key”:“encode functions”,“$”:“true”},
{“@key”:“Evictor tests per run”,“$”:“3”},
{“@key”:“Loose bbox”,“$”:“true”},
{“@key”:“Evictor run periodicity”,“$”:“300”},
{“@key”:“Estimated extends”,“$”:“true”},
{“@key”:“fetch size”,“$”:“1000”},
{“@key”:“Test while idle”,“$”:“true”},
{“@key”:“max connections”,“$”:“10”},
{“@key”:“preparedStatements”,“$”:“false”},
{“@key”:“reWriteBatchedInserts”,“$”:“false”},
{“@key”:“SSL mode”,“$”:“DISABLE”},
{“@key”:“Method used to simplify geometries”,“$”:“FAST”},
{“@key”:“schema”,“$”:“public”},
{“@key”:“create database params”,“$”:“WITH TEMPLATE=template_postgis”},
{“@key”:“Callback factory”,“$”:“PostgisNGDataStoreFactory”}
]
}
}
}
}’

Can someone explain why this happens? Is this normal behavior, a bug, or have I missed something?

Its seems I understand, the database is created when we import a file.