Sie sind auf Seite 1von 10

RESTful Web Services Methods

GET - safe operation, that doesn't make any significant changes to the state of anything POST URI identifies the resource that will handle the enclosed entity; resource : dataaccepting process, a gateway to some other protocol, or a separate entity that accepts annotations PUT - URI identifies the entity enclosed with the request; the server MUST NOT attempt to apply the request to some other resource. DELETE - requests that the origin server delete the resource identified by the Request-URI.

DEMO (1 / 9)
GET /RestWebServices/rest/itemresources HTTP/1.1 Host: localhost:8080 HTTP/1.1 200 OK Content-Type: application/xml <?xml version="1.0" encoding="UTF-8"?> <items> <item cost="7.0" id="1" name="Iced Coffee"> <link rel="/linkrels/item/order" uri="/orderresources/item/1"/> </item> <item cost="6.0" id="2" name="Hot Chocolate"> <link rel="/linkrels/item/order" uri="/orderresources/item/2"/> </item> <item cost="3.5" id="3" name="Expresso"> <link rel="/linkrels/item/order" uri="/orderresources/item/3"/> </item> <item cost="7.0" id="4" name="Caffe Latte"> <link rel="/linkrels/item/order" uri="/orderresources/item/4"/> </item> </items>

DEMO (2 / 9)
POST /RestWebServices/rest/orderresources/item/1 HTTP/1.1 Host: localhost:8080 [HTTP/1.1 201 Created] Location=[http://localhost:8080/RestWebServices/rest/orderresources/6/self] Content-Type: application/xml <?xml version="1.0" encoding="UTF-8"?> <order cost="7.0" id="6" status="UNPAID"> <items> <item cost="7.0" id="1" name="Iced Coffee"/> </items> <client id="5"/> <link rel="/linkrels/order/cancel" uri="/orderresources/6"/> <link rel="/linkrels/order/addItem" uri="/orderresources/6/items"/> <link rel="/linkrels/order/finish" uri="/orderresources/6/finish"/> </order>

DEMO (3 / 9)
GET /RestWebServices/rest/orderresources/items HTTP/1.1 Host: localhost:8080 HTTP/1.1 200 OK Content-Type: application/xml <?xml version="1.0" encoding="UTF-8"?> <order cost="7.0" id="6" status="UNPAID"> <items> <item cost="7.0" id="1" name="Iced Coffee"/> </items> <client id="5"/> <link rel="/linkrels/order/addItem" uri="/orderresources/6/item/1"/> <link rel="/linkrels/order/addItem" uri="/orderresources/6/item/2"/> <link rel="/linkrels/order/addItem" uri="/orderresources/6/item/3"/> <link rel="/linkrels/order/addItem" uri="/orderresources/6/item/4"/> </order>

DEMO (4 / 9)
PUT /RestWebServices/rest/orderresources/6/item/2 HTTP/1.1 Host: localhost:8080 HTTP/1.1 200 OK Content-Type: application/xml <?xml version="1.0" encoding="UTF-8"?> <order cost="13.0" id="6" status="UNPAID"> <items> <item cost="7.0" id="1" name="Iced Coffee"/> <item cost="6.0" id="2" name="Hot Chocolate"/> </items> <client id="5"/> <link rel="/linkrels/order/cancel" uri="/orderresources/6"/> <link rel="/linkrels/order/addItem" uri="/orderresources/6/items"/> <link rel="/linkrels/order/finish" uri="/orderresources/6/finish"/> </order>

DEMO (5 / 9)
PUT /RestWebServices/rest/orderresources/6/finish HTTP/1.1 Host: localhost:8080 HTTP/1.1 200 OK Content-Type: application/xml

<?xml version="1.0" encoding="UTF-8"?> <order cost="13.0" id="6" status="PAID"> <items> <item cost="7.0" id="1" name="Iced Coffee"/> <item cost="6.0" id="2" name="Hot Chocolate"/> </items> <client id="5"/> </order>

DEMO (6 / 9)
PUT /RestWebServices/rest/orderresources/6/item/3 HTTP/1.1 Host: localhost:8080 [HTTP/1.1 409 Conflict]

Order already paid. It cannot be modified.

DEMO (7 / 9)
GET /RestWebServices/rest/orderresources HTTP/1.1 Host: localhost:8080 HTTP/1.1 200 OK Content-Type: application/xml <?xml version="1.0" encoding="UTF-8"?> <orders> <order cost="13.0" id="6" status="PAID"> <items> <item cost="7.0" id="1" name="Iced Coffee"/> <item cost="6.0" id="2" name="Hot Chocolate"/> </items> <client id="5"/> <link rel="/linkrels/order/self" uri="/orderresources/6/self"/> </order> <order cost="3.5" id="8" status="UNPAID"> <items> <item cost="3.5" id="3" name="Expresso"/> </items> <client id="7"/> <link rel="/linkrels/order/self" uri="/orderresources/8/self"/> </order> </orders>

DEMO (8 / 9)
GET /RestWebServices/rest/orderresources/8/self HTTP/1.1 Host: localhost:8080 HTTP/1.1 200 OK Content-Type: application/xml <?xml version="1.0" encoding="UTF-8"?> <order cost="3.5" id="8" status="UNPAID"> <items> <item cost="3.5" id="3" name="Expresso"/> </items> <link rel="/linkrels/order/self" uri="/orderresources/8/self"/> <client id="7"/> <link rel="/linkrels/order/cancel" uri="/orderresources/8"/> <link rel="/linkrels/order/addItem" uri="/orderresources/8/items"/> <link rel="/linkrels/order/finish" uri="/orderresources/8/finish"/> </order>

DEMO (9 / 9)
DELETE /RestWebServices/rest/orderresources/8 HTTP/1.1 Host: localhost:8080 [HTTP/1.1 204 No Content]

DELETE /RestWebServices/rest/orderresources/20 HTTP/1.1 Host: localhost:8080 [HTTP/1.1 404 Not Found] The requested resource () is not available.

Das könnte Ihnen auch gefallen