Skip to content

REST API examples

Lorenzo Natali edited this page Jan 26, 2024 · 22 revisions

In this section you find some examples about the use of REST APIs. To run the follow commands you need cURL.

USERS LIST

curl -u admin:admin -XGET 'http://localhost:8080/geostore/rest/users'

USER ADD

curl -u admin:admin -XPOST -H 'Content-type: text/xml' -d '<User><name>username</name><newPassword>password</newPassword><role>USER</role></User>' 'http://localhost:8080/geostore/rest/users'

USER MOD

curl -u geosolutions:geosolutions -XPUT -H 'Content-type: text/xml' -d '<User><name>username</name><newPassword>password</newPassword><role>USER</role></User>' 'http://localhost:8080/geostore/rest/users/user/{ID}'

USER MOD (ATTRIBUTES)

curl -u geostore:geostore -XPUT -H 'Content-type: text/xml' -d '<User><attribute><name>attr3</name><value>value updated</value></attribute><attribute><name>attr4</name><value>98765</value></attribute><name>username</name><newPassword>password</newPassword><role>USER</role></User>' http://localhost:8080/geostore/rest/users/user/155

USER GET (ATTRIBUTES)

curl -u admin:admin -XGET http://localhost:8080/geostore/rest/users/user/155?includeattributes=true

USER DEL

To delete the user ‘name_of_user’ (where id == 65).

curl -u admin:admin -XDELETE 'http://localhost:8080/geostore/rest/users/user/65'

GROUPS LIST

curl -u admin:admin -XGET 'http://localhost:8080/geostore/rest/usergroups'

GROUP ADD

curl -u admin:admin -XPOST -H 'Content-type: text/xml' -d '<UserGroup><groupName>groupname</groupName></UserGroup>' 'http://localhost:8080/geostore/rest/usergroups'

GROUP GET

curl -u admin:admin -XGET http://localhost:8080/geostore/rest/usergroups/group/<GROUPID>

GROUP DEL

curl -u admin:admin -XDELETE http://localhost:8080/geostore/rest/usergroups/group/<GROUPID>

ASSIGN GROUP TO USER

curl -u admin:admin -XPOST http://localhost:8080/geostore/rest/usergroups/group/<USERID>/<GROUPID>

USER ADD (WITH GROUPS)

curl -u admin:admin -XPOST -H 'Content-type: text/xml' -d '<User><name>username4</name><newPassword>password4</newPassword><role>USER</role><groups><group><groupName>groupname</groupName></group></groups></User>' 'http://localhost:8080/geostore/rest/users'

ASSIGN RESOURCE PERMISSIONS TO GROUP

curl -u admin:admin -XPUT -H 'Content-type: text/xml' -d '<ResourceList><Resource><id>3</id></Resource></ResourceList>' http://localhost:8080/geostore/rest/usergroups/update_security_rules/<GROUPID>/<canRead>/<canWrite>

RESOURCES GET

curl -u user:user -XGET  'http://localhost:8080/geostore/rest/resources/resource/1'
RESOURCES GET (With Search Options)

curl -XPOST -H 'Content-type: text/xml' -d '<AND><ATTRIBUTE><name>attr</name><operator>EQUAL_TO</operator><type>STRING</type><value>val</value></ATTRIBUTE><FIELD><field>METADATA</field><operator>LIKE</operator><value>%meta%</value></FIELD></AND>' 'http://localhost:8080/geostore/rest/resources/search/list?page=0&entries=10&includeAttributes=true&includeData=true'

RESOURCES ADD

curl -u user:user -XPOST -H 'Content-type: text/xml' -d '<Resource><description></description><metadata></metadata><name>name</name><category><name>MAP</name></category><store><data><![CDATA[ {BLOB} ]]></data></store></Resource>' http://localhost:8080/geostore/rest/resources

RESOURCES ADD (unadvertised)

curl -u user:user -XPOST -H 'Content-type: text/xml' -d '<Resource><description></description><metadata></metadata><name>name</name><advertised>false</advertised><category><name>MAP</name></category><store><data><![CDATA[ {BLOB} ]]></data></store></Resource>' http://localhost:8080/geostore/rest/resources

RESOURCES ADD (ATTRIBUTES)

curl -u admin:admin -XPOST -H 'Content-type: text/xml' -d '<Resource><Attributes><attribute><name>attr1</name><type>DATE</type><value>2011-09-19 16:28:27.551</value></attribute><attribute><name>attr2</name><type>NUMBER</type><value>231424.0</value></attribute><attribute><name>attr3</name><type>STRING</type><value>text</value></attribute></Attributes><description>description</description><metadata>variuos metadata</metadata><name>resource</name><category><name>SLD</name></category><store><data>kiji</data></store></Resource>' http://localhost:8080/geostore/rest/resources     

RESOURCE GET PERMISSIONS

curl -u user:user -XGET  'http://localhost:8080/geostore/rest/resources/resource/<RESOURCE_ID>/permissions'

RESOURCE UPDATE PERMISSIONS

curl -u user:user -XPOST  -H 'Content-type: text/xml' -d '<SecurityRuleList><SecurityRule><canRead>true</canRead><canWrite>true</canWrite><user><id>3</id><name>user</name></user></SecurityRule><SecurityRule><canRead>true</canRead><canWrite>false</canWrite><group><groupName>groupname</groupName><id>2</id></group></SecurityRule></SecurityRuleList>' 'http://localhost:8080/geostore/rest/resources/resource/<RESOURCE_ID>/permissions'

CATEGORY DEL

curl -u admin:admin -XDELETE http://localhost:8080/geostore/rest/categories/category/{id}

CATEGORY ADD

curl -u geostore:geostore -XPOST -H 'Content-type: text/xml' -d '<Category><name>SLD</name></Category>' http://localhost:8080/geostore/rest/categories

see:

  • src: src/server/modules/rest/impl/src/main/resources
  • src: master@src/server/modules/rest/impl/src/main/resources
  • src: src/server/modules/rest/api/src/main/java/it/geosolutions/geostore/services/rest