First of all I hope you forgive my bad English,I'm trying to create a datastore in GeoServer using PHP so can you please give me an example that can guide me to achieve it.
The code I have is:
$app->match('/send', function() use ($app){
$curl = new Curl();
$encoder = [new XmlEncoder('datastore'), new \Symfony\Component\Serializer\Encoder\JsonEncoder()];
$normalizer = [new \Symfony\Component\Serializer\Normalizer\GetSetMethodNormalizer()];
$serializer = new \Symfony\Component\Serializer\Serializer($normalizer, $encoder);
$service = "http://localhost:8080/geoserver/"; // replace with your URL
$reqt = "rest/workspaces.xml"; // to add a new workspace
$url = $service . $reqt;
$curl->setOpt(CURLOPT_POST, True);
$curl->setBasicAuthentication('admin', 'geoserver');
$json = json_encode($curl->get($url));
$data = json_decode($json, TRUE);
$request = Request::createFromGlobals();
if($request->isMethod('POST')){
$params = [
'name' => $request->get('name'),
'type' => 'GeoTIFF',
'description' => $request->get('description'),
'url' => __DIR__ . '/' .$file->getClientOriginalName(),
'enabled' => 'on' == $request->get('enabled') ? 'true' : 'false',
];
$curl->setOpt(CURLOPT_UPLOAD, TRUE);
$json = $app['serializer']->serialize($data, 'json');
$curl->setHeader("Content-type"," application/json");
$target = "http://localhost:8080/geoserver/rest/workspaces/{$request->get('workspace')}/datastores";
return new Response($curl->post($target, $json));
}
return $app['twig']->render('form.html.twig', ['data' => array_shift($data)]);
})->bind('send');
nmtoken
13.6k5 gold badges39 silver badges91 bronze badges
1 Answer 1
There are some PHP REST samples already mentioned at this other answer but links are dead.
You can also use the samples at IBM DeveloperWorks "Get started with GeoServer and its REST API" (to download and in the post).
answered Nov 8, 2014 at 22:42
-
Thanks for your help :) i will use the php wrapper and add some things on it maybenoobdev– noobdev2014年11月08日 23:34:22 +00:00Commented Nov 8, 2014 at 23:34