From 0dd281257454d506069fc589b7f42d639332d5a9 Mon Sep 17 00:00:00 2001 From: jvelilla Date: Thu, 8 Dec 2011 20:04:39 -0200 Subject: [PATCH 01/18] Updated documentation --- examples/restbucksCRUD/readme.md | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/examples/restbucksCRUD/readme.md b/examples/restbucksCRUD/readme.md index 0d11adbe..6de86931 100644 --- a/examples/restbucksCRUD/readme.md +++ b/examples/restbucksCRUD/readme.md @@ -1,13 +1,13 @@ Restbuck Eiffel Implementation based on the book of REST in Practice - -This is an implementation of CRUD web services as is presented in the book - -Verb URI or template Use -POST /order Create a new order, and upon success, receive a Locationheader specifying the new order’s URI. -GET /order/{orderId} Request the current state of the order specified by the URI. -PUT /order/{orderId} Update an order at the given URI with new information, providing the full representation. -DELETE /order/{orderId} Logically remove the order identified by the given URI. - +==================================================================== +This is an implementation of CRUD pattern for manipulate resources + + + + + + +
Verb URI or template Use
POST /order Create a new order, and upon success, receive a Locationheader specifying the new order's URI.
GET /order/{orderId} Request the current state of the order specified by the URI.
PUT /order/{orderId} Update an order at the given URI with new information, providing the full representation.
DELETE /order/{orderId} Logically remove the order identified by the given URI.
How to Create an order From e9b7fc4c936f12ccafb59eb045921091d75aba20 Mon Sep 17 00:00:00 2001 From: jvelilla Date: Thu, 8 Dec 2011 20:28:14 -0200 Subject: [PATCH 02/18] Update examples/restbucksCRUD/readme.md --- examples/restbucksCRUD/readme.md | 76 +++++++++++++++++++++++++++++++- 1 file changed, 75 insertions(+), 1 deletion(-) diff --git a/examples/restbucksCRUD/readme.md b/examples/restbucksCRUD/readme.md index 6de86931..3da7d6df 100644 --- a/examples/restbucksCRUD/readme.md +++ b/examples/restbucksCRUD/readme.md @@ -1,6 +1,7 @@ Restbuck Eiffel Implementation based on the book of REST in Practice ==================================================================== -This is an implementation of CRUD pattern for manipulate resources +This is an implementation of CRUD pattern for manipulate resources, this is the first step to use +the HTTP protocol as an application protocol instead of a transport protocol. @@ -9,7 +10,80 @@ This is an implementation of CRUD pattern for manipulate resources
Verb URI or template Use
POST /order Create a new order, and upon success, receive a Locationheader specifying the new order's URI.
DELETE /order/{orderId} Logically remove the order identified by the given URI.
+RESTBUCKS_SERVER +--------------- + + class + RESTBUCKS_SERVER + + inherit + ANY + + URI_TEMPLATE_ROUTED_SERVICE + + DEFAULT_SERVICE + -- Here we are using a default connector using the default Nino Connector, + -- but it's possible to use other connector (CGI or FCGI). + + create + make + + feature {NONE} -- Initialization + + make + -- Initialize the router (this will have the request handler and + -- their context). + do + initialize_router + make_and_launch + end + + create_router + do + create router.make (2) + end + + setup_router + local + order_handler: ORDER_HANDLER [REQUEST_URI_TEMPLATE_HANDLER_CONTEXT] + do + create order_handler + router.map_with_request_methods ("/order", order_handler, <<"POST">>) + router.map_with_request_methods ("/order/{orderid}", order_handler, <<"GET", "DELETE", "PUT">>) + end + + feature -- Execution + + execute_default (req: WSF_REQUEST; res: WSF_RESPONSE) + -- I'm using this method to handle the method not allowed response + -- in the case that the given uri does not have a corresponding http method + -- to handle it. + local + h : HTTP_HEADER + l_description : STRING + l_api_doc : STRING + do + if req.content_length_value > 0 then + req.input.read_string (req.content_length_value.as_integer_32) + end + create h.make + h.put_status ({HTTP_STATUS_CODE}.method_not_allowed) + h.put_content_type_text_plain + l_api_doc := "%NPlease check the API%NURI:/order METHOD: POST%NURI:/order/{orderid} METHOD: GET, PUT, DELETE%N" + l_description := req.request_method + req.request_uri + " is not allowed" + "%N" + l_api_doc + h.put_content_length (l_description.count) + h.put_current_date + res.set_status_code ({HTTP_STATUS_CODE}.method_not_allowed) + res.write_header_text (h.string) + res.write_string (l_description) + end + + end + + + How to Create an order +---------------------- * Uri: http://localhost:8080/order * Method: POST From 108396bd9168877e7a122e954a082ec2a374f497 Mon Sep 17 00:00:00 2001 From: jvelilla Date: Fri, 9 Dec 2011 10:56:58 -0200 Subject: [PATCH 03/18] Update examples/restbucksCRUD/readme.md --- examples/restbucksCRUD/readme.md | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/examples/restbucksCRUD/readme.md b/examples/restbucksCRUD/readme.md index 3da7d6df..106275f8 100644 --- a/examples/restbucksCRUD/readme.md +++ b/examples/restbucksCRUD/readme.md @@ -11,7 +11,13 @@ the HTTP protocol as an application protocol instead of a transport protocol. RESTBUCKS_SERVER ---------------- +---------------- +This class implement the main entry of our REST CRUD service, we are using a default connector (Nino Connector, +using a WebServer written in Eiffel). +We are inheriting from URI_TEMPLATE_ROUTED_SERVICE, this allows us to map our service contrat, as is shown in the previous +table, the mapping is defined in the feature setup_router, this also show that the class ORDER_HANDLER will be encharge +of to handle different type of request to the ORDER resource. + class RESTBUCKS_SERVER From 2dd43ad8293f0115486940761694e184475151e0 Mon Sep 17 00:00:00 2001 From: jvelilla Date: Fri, 9 Dec 2011 11:02:31 -0200 Subject: [PATCH 04/18] Update examples/restbucksCRUD/readme.md --- examples/restbucksCRUD/readme.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/examples/restbucksCRUD/readme.md b/examples/restbucksCRUD/readme.md index 106275f8..36079cef 100644 --- a/examples/restbucksCRUD/readme.md +++ b/examples/restbucksCRUD/readme.md @@ -130,3 +130,8 @@ How to Delete an order * Uri: http://localhost:8080/order/{order_id} * Method: DELETE + +References +---------- +1. [How to get a cup of coffe](http://www.infoq.com/articles/webber-rest-workflow) +2. [Rest in Practice] (http://restinpractice.com/default.aspx) From a70e75f729b7258cdba81781917025d77c8df15f Mon Sep 17 00:00:00 2001 From: jvelilla Date: Fri, 9 Dec 2011 11:41:58 -0200 Subject: [PATCH 05/18] Update examples/restbucksCRUD/readme.md --- examples/restbucksCRUD/readme.md | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/examples/restbucksCRUD/readme.md b/examples/restbucksCRUD/readme.md index 36079cef..95980042 100644 --- a/examples/restbucksCRUD/readme.md +++ b/examples/restbucksCRUD/readme.md @@ -1,7 +1,11 @@ Restbuck Eiffel Implementation based on the book of REST in Practice ==================================================================== -This is an implementation of CRUD pattern for manipulate resources, this is the first step to use +This is an ihmplementation of CRUD pattern for manipulate resources, this is the first step to use the HTTP protocol as an application protocol instead of a transport protocol. + +Restbuck Protocol +----------------- + @@ -10,6 +14,14 @@ the HTTP protocol as an application protocol instead of a transport protocol.
Verb URI or template Use
POST /order Create a new order, and upon success, receive a Locationheader specifying the new order's URI.
DELETE /order/{orderId} Logically remove the order identified by the given URI.
+Resource Represenation +---------------------- +The previous tables shows a contrat, the URI or URI template, allows us to indentify resources, now we will chose a +representacion, for this particular case we will use JSON. + +Note: _A resource can have multiple URIs_ + _A resource can have multuple Representations_ + RESTBUCKS_SERVER ---------------- This class implement the main entry of our REST CRUD service, we are using a default connector (Nino Connector, From f6f94add80d3800bbf41bff40e38c3987ac0268d Mon Sep 17 00:00:00 2001 From: jvelilla Date: Fri, 9 Dec 2011 11:43:58 -0200 Subject: [PATCH 06/18] Update examples/restbucksCRUD/readme.md --- examples/restbucksCRUD/readme.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/examples/restbucksCRUD/readme.md b/examples/restbucksCRUD/readme.md index 95980042..63582434 100644 --- a/examples/restbucksCRUD/readme.md +++ b/examples/restbucksCRUD/readme.md @@ -19,8 +19,9 @@ Resource Represenation The previous tables shows a contrat, the URI or URI template, allows us to indentify resources, now we will chose a representacion, for this particular case we will use JSON. -Note: _A resource can have multiple URIs_ - _A resource can have multuple Representations_ +Note: + * _A resource can have multiple URIs_ + * _A resource can have multuple Representations_ RESTBUCKS_SERVER ---------------- From f601ae1c8b8dbb489f51a0407604e28a04ae42ae Mon Sep 17 00:00:00 2001 From: jvelilla Date: Fri, 9 Dec 2011 11:52:18 -0200 Subject: [PATCH 07/18] Update examples/restbucksCRUD/readme.md --- examples/restbucksCRUD/readme.md | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/examples/restbucksCRUD/readme.md b/examples/restbucksCRUD/readme.md index 63582434..8f5a759a 100644 --- a/examples/restbucksCRUD/readme.md +++ b/examples/restbucksCRUD/readme.md @@ -19,9 +19,9 @@ Resource Represenation The previous tables shows a contrat, the URI or URI template, allows us to indentify resources, now we will chose a representacion, for this particular case we will use JSON. -Note: - * _A resource can have multiple URIs_ - * _A resource can have multuple Representations_ +Note:
+1. *A resource can have multiple URIs*.
+2. *A resource can have multiple Representations*.
RESTBUCKS_SERVER ---------------- @@ -128,6 +128,7 @@ How to Create an order How to Read an order +-------------------- * Uri: http://localhost:8080/order/{order_id} * Method: GET @@ -135,11 +136,13 @@ How to Read an order How to Update an order +---------------------- * Uri: http://localhost:8080/order/{order_id} * Method: PUT How to Delete an order +---------------------- * Uri: http://localhost:8080/order/{order_id} * Method: DELETE From de157be6f1886a22eac3121f2a09885a294bf78f Mon Sep 17 00:00:00 2001 From: jvelilla Date: Fri, 9 Dec 2011 11:57:04 -0200 Subject: [PATCH 08/18] Update examples/restbucksCRUD/readme.md --- examples/restbucksCRUD/readme.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/examples/restbucksCRUD/readme.md b/examples/restbucksCRUD/readme.md index 8f5a759a..300c2c1c 100644 --- a/examples/restbucksCRUD/readme.md +++ b/examples/restbucksCRUD/readme.md @@ -104,6 +104,14 @@ of to handle different type of request to the ORDER resource. How to Create an order ---------------------- +Here is the convention that we are using +POST is used for creation and the server determines the URI of the created resource. +If the request post is SUCCESS, the server will create the order and will response with +HTTP_RESPONSE 201 CREATED, the Location header will contains the newly created order's URI +if the request post is not SUCCESS, the server will response with +HTTP_RESPONSE 400 BAD REQUEST, the client send a bad request or +HTTP_RESPONSE 500 INTERNAL_SERVER_ERROR, when the server can deliver the request. + * Uri: http://localhost:8080/order * Method: POST * Note: you will get in the response the "location" of the new your order. From 5e2c2af18a83458e94c0d0d3c90fccae7b00294b Mon Sep 17 00:00:00 2001 From: jvelilla Date: Fri, 9 Dec 2011 11:57:47 -0200 Subject: [PATCH 09/18] Update examples/restbucksCRUD/readme.md --- examples/restbucksCRUD/readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/restbucksCRUD/readme.md b/examples/restbucksCRUD/readme.md index 300c2c1c..b0a57cad 100644 --- a/examples/restbucksCRUD/readme.md +++ b/examples/restbucksCRUD/readme.md @@ -104,7 +104,7 @@ of to handle different type of request to the ORDER resource. How to Create an order ---------------------- -Here is the convention that we are using +Here is the convention that we are using: POST is used for creation and the server determines the URI of the created resource. If the request post is SUCCESS, the server will create the order and will response with HTTP_RESPONSE 201 CREATED, the Location header will contains the newly created order's URI From 5d17b0dd29b22fc008ac6505f605ebda7836310a Mon Sep 17 00:00:00 2001 From: jvelilla Date: Fri, 9 Dec 2011 17:24:01 -0200 Subject: [PATCH 10/18] Update examples/restbucksCRUD/readme.md --- examples/restbucksCRUD/readme.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/examples/restbucksCRUD/readme.md b/examples/restbucksCRUD/readme.md index b0a57cad..4cc42798 100644 --- a/examples/restbucksCRUD/readme.md +++ b/examples/restbucksCRUD/readme.md @@ -106,11 +106,11 @@ How to Create an order Here is the convention that we are using: POST is used for creation and the server determines the URI of the created resource. -If the request post is SUCCESS, the server will create the order and will response with -HTTP_RESPONSE 201 CREATED, the Location header will contains the newly created order's URI -if the request post is not SUCCESS, the server will response with -HTTP_RESPONSE 400 BAD REQUEST, the client send a bad request or -HTTP_RESPONSE 500 INTERNAL_SERVER_ERROR, when the server can deliver the request. +If the request POST is SUCCESS, the server will create the order and will response with +201 CREATED, the Location header will contains the newly created order's URI, +if the request POST is not SUCCESS, the server will response with +400 BAD REQUEST, the client send a bad request or +500 INTERNAL_SERVER_ERROR, when the server can deliver the request. * Uri: http://localhost:8080/order * Method: POST From 0aa3d81b2268b987125716917d3c856a2bb04266 Mon Sep 17 00:00:00 2001 From: jvelilla Date: Fri, 9 Dec 2011 18:44:21 -0200 Subject: [PATCH 11/18] Update examples/restbucksCRUD/readme.md --- examples/restbucksCRUD/readme.md | 64 +++++++++++++++++++++----------- 1 file changed, 43 insertions(+), 21 deletions(-) diff --git a/examples/restbucksCRUD/readme.md b/examples/restbucksCRUD/readme.md index 4cc42798..5719870d 100644 --- a/examples/restbucksCRUD/readme.md +++ b/examples/restbucksCRUD/readme.md @@ -101,8 +101,8 @@ of to handle different type of request to the ORDER resource. -How to Create an order ----------------------- +How to Create an order with POST +-------------------------------- Here is the convention that we are using: POST is used for creation and the server determines the URI of the created resource. @@ -112,27 +112,49 @@ if the request POST is not SUCCESS, the server will response with 400 BAD REQUEST, the client send a bad request or 500 INTERNAL_SERVER_ERROR, when the server can deliver the request. - * Uri: http://localhost:8080/order - * Method: POST - * Note: you will get in the response the "location" of the new your order. - * HEADERS: - - Content-Type: application/json - - * Example CONTENT +POST /order HTTP/1.1 +Host: 127.0.0.1:8080 +Connection: keep-alive +Content-Length: 196 +Origin: chrome-extension://fhjcajmcbmldlhcimfajhfbgofnpcjmb +Content-Type: application/json +Accept: */* +Accept-Encoding: gzip,deflate,sdch +Accept-Language: es-419,es;q=0.8,en;q=0.6 +Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3 - { - "location":"takeAway", - "items":[ - { - "name":"Late", - "option":"skim", - "size":"Small", - "quantity":1 - } - ] - } +{ + "location":"takeAway", + "items":[ + { + "name":"Late", + "option":"skim", + "size":"Small", + "quantity":1 + } + ] +} +Response success + +HTTP/1.1 201 Created +Status 201 Created +Content-Type application/json +Content-Length 123 +Location http://localhost:8080/order/1 +Date FRI,09 DEC 2011 20:34:20.00 GMT + +{ + "id" : "1", + "location" : "takeAway", + "status" : "submitted", + "items" : [ { + "name" : "late", + "size" : "small", + "quantity" : 1, + "option" : "skim" + } ] +} How to Read an order From 9ef10c749a28a7d09a8e2d9eb039ef5c064f98db Mon Sep 17 00:00:00 2001 From: jvelilla Date: Fri, 9 Dec 2011 18:45:50 -0200 Subject: [PATCH 12/18] Update examples/restbucksCRUD/readme.md --- examples/restbucksCRUD/readme.md | 80 ++++++++++++++++---------------- 1 file changed, 40 insertions(+), 40 deletions(-) diff --git a/examples/restbucksCRUD/readme.md b/examples/restbucksCRUD/readme.md index 5719870d..4b012c4d 100644 --- a/examples/restbucksCRUD/readme.md +++ b/examples/restbucksCRUD/readme.md @@ -112,49 +112,49 @@ if the request POST is not SUCCESS, the server will response with 400 BAD REQUEST, the client send a bad request or 500 INTERNAL_SERVER_ERROR, when the server can deliver the request. -POST /order HTTP/1.1 -Host: 127.0.0.1:8080 -Connection: keep-alive -Content-Length: 196 -Origin: chrome-extension://fhjcajmcbmldlhcimfajhfbgofnpcjmb -Content-Type: application/json -Accept: */* -Accept-Encoding: gzip,deflate,sdch -Accept-Language: es-419,es;q=0.8,en;q=0.6 -Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3 - -{ - "location":"takeAway", - "items":[ - { - "name":"Late", - "option":"skim", - "size":"Small", - "quantity":1 - } - ] -} + POST /order HTTP/1.1 + Host: 127.0.0.1:8080 + Connection: keep-alive + Content-Length: 196 + Origin: chrome-extension://fhjcajmcbmldlhcimfajhfbgofnpcjmb + Content-Type: application/json + Accept: */* + Accept-Encoding: gzip,deflate,sdch + Accept-Language: es-419,es;q=0.8,en;q=0.6 + Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3 + + { + "location":"takeAway", + "items":[ + { + "name":"Late", + "option":"skim", + "size":"Small", + "quantity":1 + } + ] + } Response success -HTTP/1.1 201 Created -Status 201 Created -Content-Type application/json -Content-Length 123 -Location http://localhost:8080/order/1 -Date FRI,09 DEC 2011 20:34:20.00 GMT - -{ - "id" : "1", - "location" : "takeAway", - "status" : "submitted", - "items" : [ { - "name" : "late", - "size" : "small", - "quantity" : 1, - "option" : "skim" - } ] -} + HTTP/1.1 201 Created + Status 201 Created + Content-Type application/json + Content-Length 123 + Location http://localhost:8080/order/1 + Date FRI,09 DEC 2011 20:34:20.00 GMT + + { + "id" : "1", + "location" : "takeAway", + "status" : "submitted", + "items" : [ { + "name" : "late", + "size" : "small", + "quantity" : 1, + "option" : "skim" + } ] + } How to Read an order From b96029a7500d075b87063c0741a63d221a616cce Mon Sep 17 00:00:00 2001 From: jvelilla Date: Fri, 9 Dec 2011 18:56:49 -0200 Subject: [PATCH 13/18] Update examples/restbucksCRUD/readme.md --- examples/restbucksCRUD/readme.md | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/examples/restbucksCRUD/readme.md b/examples/restbucksCRUD/readme.md index 4b012c4d..1c292b84 100644 --- a/examples/restbucksCRUD/readme.md +++ b/examples/restbucksCRUD/readme.md @@ -159,9 +159,30 @@ Response success How to Read an order -------------------- - * Uri: http://localhost:8080/order/{order_id} - * Method: GET +Using GET to retrieve resource information. +If the GET request is SUCCESS, we response with 200 OK, and a representation of the order +If the GET request is not SUCCESS, we response with 404 Resource not found +If is a Conditional GET and the resource does not change we send a 304, Resource not modifed + HTTP/1.1 200 OK + + Status 200 OK + Content-Type application/json + Content-Length 123 + Date FRI,09 DEC 2011 20:53:46.00 GMT + etag 2ED3A40954A95D766FC155682DC8BB52 + + { + "id" : "1", + "location" : "takeAway", + "status" : "submitted", + "items" : [ { + "name" : "late", + "size" : "small", + "quantity" : 1, + "option" : "skim" + } ] + } From f27c1f97a31a799040fa3868e428d1ef8ae632b1 Mon Sep 17 00:00:00 2001 From: jvelilla Date: Fri, 9 Dec 2011 18:59:23 -0200 Subject: [PATCH 14/18] Update examples/restbucksCRUD/readme.md --- examples/restbucksCRUD/readme.md | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/examples/restbucksCRUD/readme.md b/examples/restbucksCRUD/readme.md index 1c292b84..84299d10 100644 --- a/examples/restbucksCRUD/readme.md +++ b/examples/restbucksCRUD/readme.md @@ -188,9 +188,14 @@ If is a Conditional GET and the resource does not change we send a 304, Resource How to Update an order ---------------------- - * Uri: http://localhost:8080/order/{order_id} - * Method: PUT - +Updating a resource with PUT. +A successful PUT request will not create a new resource, instead it will change the state of the resource identified by the current uri. +If success we response with 200 and the updated order. +404 if the order is not found +400 in case of a bad request +500 internal server error +If the request is a Conditional PUT, and it does not mat we response 415, precondition failed. + How to Delete an order ---------------------- From 7495d0e6a794f55639996e2fd8c1fae1f08c4418 Mon Sep 17 00:00:00 2001 From: jvelilla Date: Fri, 9 Dec 2011 19:00:58 -0200 Subject: [PATCH 15/18] Update examples/restbucksCRUD/readme.md --- examples/restbucksCRUD/readme.md | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/examples/restbucksCRUD/readme.md b/examples/restbucksCRUD/readme.md index 84299d10..e778c842 100644 --- a/examples/restbucksCRUD/readme.md +++ b/examples/restbucksCRUD/readme.md @@ -199,8 +199,12 @@ If the request is a Conditional PUT, and it does not mat we response 415, precon How to Delete an order ---------------------- - * Uri: http://localhost:8080/order/{order_id} - * Method: DELETE +Here we use DELETE to cancel an order, if that order is in state where it can still be canceled. +200 if is ok +404 Resource not found +405 if consumer and service's view of the resouce state is inconsisent +500 if we have an internal server error + References From 5ef19021eb30843ae3493fe3d857e0a75e21e72b Mon Sep 17 00:00:00 2001 From: jvelilla Date: Fri, 9 Dec 2011 19:10:09 -0200 Subject: [PATCH 16/18] Update examples/restbucksCRUD/readme.md --- examples/restbucksCRUD/readme.md | 61 +++++++++++++++++++++++++++----- 1 file changed, 53 insertions(+), 8 deletions(-) diff --git a/examples/restbucksCRUD/readme.md b/examples/restbucksCRUD/readme.md index e778c842..e6e97db9 100644 --- a/examples/restbucksCRUD/readme.md +++ b/examples/restbucksCRUD/readme.md @@ -157,8 +157,8 @@ Response success } -How to Read an order --------------------- +How to Read an order with GET +----------------------------- Using GET to retrieve resource information. If the GET request is SUCCESS, we response with 200 OK, and a representation of the order If the GET request is not SUCCESS, we response with 404 Resource not found @@ -186,19 +186,64 @@ If is a Conditional GET and the resource does not change we send a 304, Resource -How to Update an order ----------------------- -Updating a resource with PUT. +How to Update an order with PUT +------------------------------- A successful PUT request will not create a new resource, instead it will change the state of the resource identified by the current uri. If success we response with 200 and the updated order. 404 if the order is not found 400 in case of a bad request 500 internal server error If the request is a Conditional PUT, and it does not mat we response 415, precondition failed. - -How to Delete an order ----------------------- +Suposse that we had created an Order with the values shown in the _How to create an order with POST_ +But we change our decision and we want to stay in the shop. + + + + PUT /order/1 HTTP/1.1 + Content-Length: 122 + Content-Type: application/json; charset=UTF-8 + Host: localhost:8080 + Connection: Keep-Alive + User-Agent: Apache-HttpClient/4.0-beta2 (java 1.5) + Expect: 100-Continue + + { + "id" : "1", + "location" : "in shop", + "status" : "submitted", + "items" : [ { + "name" : "late", + "size" : "small", + "quantity" : 1, + "option" : "skim" + } ] + } + + +Response success + + HTTP/1.1 200 OK + Status 200 OK + Content-Type application/json + Date FRI,09 DEC 2011 21:06:26.00 GMT + etag 8767F900674B843E1F3F70BCF3E62403 + Content-Length 122 + + { + "id" : "1", + "location" : "in shop", + "status" : "submitted", + "items" : [ { + "name" : "late", + "size" : "small", + "quantity" : 1, + "option" : "skim" + } ] + } + +How to Delete an order with DELETE +---------------------------------- Here we use DELETE to cancel an order, if that order is in state where it can still be canceled. 200 if is ok 404 Resource not found From 9a85c24c0d6025234e600608d7aaab8dcc4f4752 Mon Sep 17 00:00:00 2001 From: jvelilla Date: Fri, 9 Dec 2011 19:15:33 -0200 Subject: [PATCH 17/18] Update examples/restbucksCRUD/readme.md --- examples/restbucksCRUD/readme.md | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/examples/restbucksCRUD/readme.md b/examples/restbucksCRUD/readme.md index e6e97db9..f69fe633 100644 --- a/examples/restbucksCRUD/readme.md +++ b/examples/restbucksCRUD/readme.md @@ -205,7 +205,6 @@ But we change our decision and we want to stay in the shop. Content-Type: application/json; charset=UTF-8 Host: localhost:8080 Connection: Keep-Alive - User-Agent: Apache-HttpClient/4.0-beta2 (java 1.5) Expect: 100-Continue { @@ -245,12 +244,41 @@ Response success How to Delete an order with DELETE ---------------------------------- Here we use DELETE to cancel an order, if that order is in state where it can still be canceled. -200 if is ok +204 if is ok 404 Resource not found 405 if consumer and service's view of the resouce state is inconsisent 500 if we have an internal server error + DELETE /order/1 HTTP/1.1 + Host: localhost:8080 + Connection: Keep-Alive + +Response success + + HTTP/1.1 204 No Content + + Status 204 No Content + Content-Type application/json + Date FRI,09 DEC 2011 21:10:51.00 GMT + +If we want to check that the resource does not exist anymore we can try to retrieve a GET /order/1 and we will receive a +404 No Found + + GET /order/1 HTTP/1.1 + Host: localhost:8080 + Connection: Keep-Alive + +Response + HTTP/1.1 404 Not Found + + Status 404 Not Found + Content-Type application/json + Content-Length 44 + Date FRI,09 DEC 2011 21:14:17.79 GMT + + The following resource/order/1 is not found + References ---------- From 36601fd3a496f9a25e82e62254ac124250c4cefb Mon Sep 17 00:00:00 2001 From: jvelilla Date: Fri, 9 Dec 2011 19:16:07 -0200 Subject: [PATCH 18/18] Update examples/restbucksCRUD/readme.md --- examples/restbucksCRUD/readme.md | 1 + 1 file changed, 1 insertion(+) diff --git a/examples/restbucksCRUD/readme.md b/examples/restbucksCRUD/readme.md index f69fe633..f17c04d9 100644 --- a/examples/restbucksCRUD/readme.md +++ b/examples/restbucksCRUD/readme.md @@ -270,6 +270,7 @@ If we want to check that the resource does not exist anymore we can try to retri Connection: Keep-Alive Response + HTTP/1.1 404 Not Found Status 404 Not Found