46.5. Komunikace s REST serverem pomocí curl

Odkazy:

POST

curl -i -H "Accept: application/json" -X POST -d "firstName=james" http
curl -X POST -H 'Content-type: text/xml' -d '<xml><login>john</login><password>123456</password></xml>' http://0.0.0.0:3000/users
curl -i POST -u "user:password" -H "Content-Type: application/xml" -d "<Foo></Foo>" http://example.org/resource

PUT

curl -i -H "Accept: application/json" -X PUT -d "phone=1-800-999-9999" h

GET

curl -i -H "Accept: application/json" http://192.168.0.165/persons/per

DELETE

curl -i -H "Accept: application/json" -X DELETE http://192.168.0.165/per

Operace GET mi funguje

$ curl  http://cl-control.appspot.com/rest/apothecary
<?xml version="1.0" encoding="utf-8"?><list offset=""><apothecary><key>agpjbC1jb250cm9schELEgpBcG90aGVjYXJ5GOkHDA</key><when>2010-11-20T10:04:45.732402</when><stredisko>123</stredisko></apothecary></list>r</computeroutput>

Operace DELETE mi taky funguje

$ curl -X DELETE http://cl-control.appspot.com/rest/apothecary/agpjbC1jb250cm9schELEgpBcG90aGVjYXJ5GNEPDA

Vytvoření nového záznamu, podle postupu:

    * Gets the single <typeName> instance with the given <key> 

# POST http://<service>/rest/<typeName>

    * Create new <typeName> instance using the posted data which should adhere to the XML Schema for the type
    * Returns the key of the new instance by default. With "?type=full" at the end of the url, returns the entire updated instance like a GET request. </typeName>

Po chvilce zkoumání chyb jsem přišel s následujícím XML tvarem.

#!/bin/bash
URI="http://cl-control.appspot.com/rest/apothecary"

curl -X PUT $URI -d '<?xml version="1.0"?>
<apothecary>
  <stredisko>13</stredisko>
  <hostname>tester</hostname>
</apothecary>'
Licence Creative Commons
Tento dokument Ruby, jehož autorem je Radek Hnilica, podléhá licenci Creative Commons Uveďte autora-Nevyužívejte dílo komerčně-Zachovejte licenci 3.0 Česká republika .