From 39b5a70979d0ff937291624623eced85584b858b Mon Sep 17 00:00:00 2001 From: jvelilla Date: Wed, 7 Dec 2011 07:22:51 -0300 Subject: [PATCH 01/24] Sync Jocelyn repo --- contrib/ise_library/cURL | 2 +- contrib/library/text/parser/json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/contrib/ise_library/cURL b/contrib/ise_library/cURL index f17f785e..2b7043f6 160000 --- a/contrib/ise_library/cURL +++ b/contrib/ise_library/cURL @@ -1 +1 @@ -Subproject commit f17f785ee36db5b424ce40dfcd7bbd41924613bc +Subproject commit 2b7043f670f6efc70ebed5fbf62d83a22c095ffe diff --git a/contrib/library/text/parser/json b/contrib/library/text/parser/json index 5ec1bdd2..24d08d4f 160000 --- a/contrib/library/text/parser/json +++ b/contrib/library/text/parser/json @@ -1 +1 @@ -Subproject commit 5ec1bdd2ea01358153de6887f572bdb2e70c02dd +Subproject commit 24d08d4fcedf1d54f1c8b4eb6526f2dd1b2fb943 From 3313e9cf818978afbce003ec46dd44effc68a484 Mon Sep 17 00:00:00 2001 From: jvelilla Date: Thu, 8 Dec 2011 18:43:29 -0300 Subject: [PATCH 02/24] Added basic two basic examples, refactor rename restbucks to restbucksCRUD --- .../client/README.txt | 0 .../client/client-safe.ecf | 0 .../client/client.ecf | 0 .../client/src/restbuck_client.e | 0 .../{restbucks => restbucksCRUD}/license.lic | 0 .../{restbucks => restbucksCRUD}/readme.txt | 0 .../restbucks-safe.ecf | 0 .../{restbucks => restbucksCRUD}/restbucks.rc | 0 .../src/database/database_api.e | 0 .../src/database/shared_database_api.e | 0 .../src/domain/item.e | 0 .../src/domain/item_constants.e | 0 .../src/domain/json_order_converter.e | 0 .../src/domain/order.e | 0 .../src/domain/order_validation.e | 0 .../src/domain/shared_order_validation.e | 0 .../src/resource/order_handler.e | 0 .../src/restbucks_server.e | 0 .../src/utils/etag_utils.e | 0 examples/simple/application.e | 31 +++++++++++++ examples/simple/simple.ecf | 24 +++++++++++ examples/simple/simple.rc | 1 + examples/simple_file/home.html | 13 ++++++ examples/simple_file/service_file.e | 43 +++++++++++++++++++ examples/simple_file/service_file.ecf | 24 +++++++++++ examples/simple_file/service_file.rc | 1 + 26 files changed, 137 insertions(+) rename examples/{restbucks => restbucksCRUD}/client/README.txt (100%) rename examples/{restbucks => restbucksCRUD}/client/client-safe.ecf (100%) rename examples/{restbucks => restbucksCRUD}/client/client.ecf (100%) rename examples/{restbucks => restbucksCRUD}/client/src/restbuck_client.e (100%) rename examples/{restbucks => restbucksCRUD}/license.lic (100%) rename examples/{restbucks => restbucksCRUD}/readme.txt (100%) rename examples/{restbucks => restbucksCRUD}/restbucks-safe.ecf (100%) rename examples/{restbucks => restbucksCRUD}/restbucks.rc (100%) rename examples/{restbucks => restbucksCRUD}/src/database/database_api.e (100%) rename examples/{restbucks => restbucksCRUD}/src/database/shared_database_api.e (100%) rename examples/{restbucks => restbucksCRUD}/src/domain/item.e (100%) rename examples/{restbucks => restbucksCRUD}/src/domain/item_constants.e (100%) rename examples/{restbucks => restbucksCRUD}/src/domain/json_order_converter.e (100%) rename examples/{restbucks => restbucksCRUD}/src/domain/order.e (100%) rename examples/{restbucks => restbucksCRUD}/src/domain/order_validation.e (100%) rename examples/{restbucks => restbucksCRUD}/src/domain/shared_order_validation.e (100%) rename examples/{restbucks => restbucksCRUD}/src/resource/order_handler.e (100%) rename examples/{restbucks => restbucksCRUD}/src/restbucks_server.e (100%) rename examples/{restbucks => restbucksCRUD}/src/utils/etag_utils.e (100%) create mode 100644 examples/simple/application.e create mode 100644 examples/simple/simple.ecf create mode 100644 examples/simple/simple.rc create mode 100644 examples/simple_file/home.html create mode 100644 examples/simple_file/service_file.e create mode 100644 examples/simple_file/service_file.ecf create mode 100644 examples/simple_file/service_file.rc diff --git a/examples/restbucks/client/README.txt b/examples/restbucksCRUD/client/README.txt similarity index 100% rename from examples/restbucks/client/README.txt rename to examples/restbucksCRUD/client/README.txt diff --git a/examples/restbucks/client/client-safe.ecf b/examples/restbucksCRUD/client/client-safe.ecf similarity index 100% rename from examples/restbucks/client/client-safe.ecf rename to examples/restbucksCRUD/client/client-safe.ecf diff --git a/examples/restbucks/client/client.ecf b/examples/restbucksCRUD/client/client.ecf similarity index 100% rename from examples/restbucks/client/client.ecf rename to examples/restbucksCRUD/client/client.ecf diff --git a/examples/restbucks/client/src/restbuck_client.e b/examples/restbucksCRUD/client/src/restbuck_client.e similarity index 100% rename from examples/restbucks/client/src/restbuck_client.e rename to examples/restbucksCRUD/client/src/restbuck_client.e diff --git a/examples/restbucks/license.lic b/examples/restbucksCRUD/license.lic similarity index 100% rename from examples/restbucks/license.lic rename to examples/restbucksCRUD/license.lic diff --git a/examples/restbucks/readme.txt b/examples/restbucksCRUD/readme.txt similarity index 100% rename from examples/restbucks/readme.txt rename to examples/restbucksCRUD/readme.txt diff --git a/examples/restbucks/restbucks-safe.ecf b/examples/restbucksCRUD/restbucks-safe.ecf similarity index 100% rename from examples/restbucks/restbucks-safe.ecf rename to examples/restbucksCRUD/restbucks-safe.ecf diff --git a/examples/restbucks/restbucks.rc b/examples/restbucksCRUD/restbucks.rc similarity index 100% rename from examples/restbucks/restbucks.rc rename to examples/restbucksCRUD/restbucks.rc diff --git a/examples/restbucks/src/database/database_api.e b/examples/restbucksCRUD/src/database/database_api.e similarity index 100% rename from examples/restbucks/src/database/database_api.e rename to examples/restbucksCRUD/src/database/database_api.e diff --git a/examples/restbucks/src/database/shared_database_api.e b/examples/restbucksCRUD/src/database/shared_database_api.e similarity index 100% rename from examples/restbucks/src/database/shared_database_api.e rename to examples/restbucksCRUD/src/database/shared_database_api.e diff --git a/examples/restbucks/src/domain/item.e b/examples/restbucksCRUD/src/domain/item.e similarity index 100% rename from examples/restbucks/src/domain/item.e rename to examples/restbucksCRUD/src/domain/item.e diff --git a/examples/restbucks/src/domain/item_constants.e b/examples/restbucksCRUD/src/domain/item_constants.e similarity index 100% rename from examples/restbucks/src/domain/item_constants.e rename to examples/restbucksCRUD/src/domain/item_constants.e diff --git a/examples/restbucks/src/domain/json_order_converter.e b/examples/restbucksCRUD/src/domain/json_order_converter.e similarity index 100% rename from examples/restbucks/src/domain/json_order_converter.e rename to examples/restbucksCRUD/src/domain/json_order_converter.e diff --git a/examples/restbucks/src/domain/order.e b/examples/restbucksCRUD/src/domain/order.e similarity index 100% rename from examples/restbucks/src/domain/order.e rename to examples/restbucksCRUD/src/domain/order.e diff --git a/examples/restbucks/src/domain/order_validation.e b/examples/restbucksCRUD/src/domain/order_validation.e similarity index 100% rename from examples/restbucks/src/domain/order_validation.e rename to examples/restbucksCRUD/src/domain/order_validation.e diff --git a/examples/restbucks/src/domain/shared_order_validation.e b/examples/restbucksCRUD/src/domain/shared_order_validation.e similarity index 100% rename from examples/restbucks/src/domain/shared_order_validation.e rename to examples/restbucksCRUD/src/domain/shared_order_validation.e diff --git a/examples/restbucks/src/resource/order_handler.e b/examples/restbucksCRUD/src/resource/order_handler.e similarity index 100% rename from examples/restbucks/src/resource/order_handler.e rename to examples/restbucksCRUD/src/resource/order_handler.e diff --git a/examples/restbucks/src/restbucks_server.e b/examples/restbucksCRUD/src/restbucks_server.e similarity index 100% rename from examples/restbucks/src/restbucks_server.e rename to examples/restbucksCRUD/src/restbucks_server.e diff --git a/examples/restbucks/src/utils/etag_utils.e b/examples/restbucksCRUD/src/utils/etag_utils.e similarity index 100% rename from examples/restbucks/src/utils/etag_utils.e rename to examples/restbucksCRUD/src/utils/etag_utils.e diff --git a/examples/simple/application.e b/examples/simple/application.e new file mode 100644 index 00000000..887d4ec4 --- /dev/null +++ b/examples/simple/application.e @@ -0,0 +1,31 @@ +note + description : "simple application root class" + date : "$Date$" + revision : "$Revision$" + +class + APPLICATION + +inherit + DEFAULT_SERVICE + +create + make + +feature {NONE} -- Initialization + + make + -- Run application. + do + make_and_launch + end + + execute (req: WSF_REQUEST; res: WSF_RESPONSE) + do + -- To send a response we need to setup, the status code and + -- the response headers. + res.set_status_code ({HTTP_STATUS_CODE}.ok) + res.write_header_text ("") + res.write_string ("Hello World") + end +end diff --git a/examples/simple/simple.ecf b/examples/simple/simple.ecf new file mode 100644 index 00000000..6dfd06eb --- /dev/null +++ b/examples/simple/simple.ecf @@ -0,0 +1,24 @@ + + + + + + + + + + + + + /EIFGENs$ + /CVS$ + /.svn$ + + + + + + + diff --git a/examples/simple/simple.rc b/examples/simple/simple.rc new file mode 100644 index 00000000..8b137891 --- /dev/null +++ b/examples/simple/simple.rc @@ -0,0 +1 @@ + diff --git a/examples/simple_file/home.html b/examples/simple_file/home.html new file mode 100644 index 00000000..35ab8098 --- /dev/null +++ b/examples/simple_file/home.html @@ -0,0 +1,13 @@ + + + Eiffel REST services + + + + Welcome to the Eiffel REST services site, here you will find a lot of
+ resources about REST and our solution + + + + + \ No newline at end of file diff --git a/examples/simple_file/service_file.e b/examples/simple_file/service_file.e new file mode 100644 index 00000000..44fd3796 --- /dev/null +++ b/examples/simple_file/service_file.e @@ -0,0 +1,43 @@ +note + description : "simple application root class" + date : "$Date$" + revision : "$Revision$" + +class + SERVICE_FILE + +inherit + DEFAULT_SERVICE + +create + make + +feature {NONE} -- Initialization + + make + -- Run application. + do + make_and_launch + end + + execute (req: WSF_REQUEST; res: WSF_RESPONSE) + local + l_file : RAW_FILE + message : STRING + h : WSF_HEADER + do + create l_file.make_open_read ("home.html") + l_file.read_stream (l_file.count) + message := l_file.last_string + l_file.close + + -- To send a response we need to setup, the status code and + -- the response headers. + create h.make + h.put_content_type_text_html + h.put_content_length (l_file.count) + res.set_status_code ({HTTP_STATUS_CODE}.ok) + res.write_header_text (h.string) + res.write_string (message) + end +end diff --git a/examples/simple_file/service_file.ecf b/examples/simple_file/service_file.ecf new file mode 100644 index 00000000..e930b050 --- /dev/null +++ b/examples/simple_file/service_file.ecf @@ -0,0 +1,24 @@ + + + + + + + + + + + + + /EIFGENs$ + /CVS$ + /.svn$ + + + + + + + diff --git a/examples/simple_file/service_file.rc b/examples/simple_file/service_file.rc new file mode 100644 index 00000000..8b137891 --- /dev/null +++ b/examples/simple_file/service_file.rc @@ -0,0 +1 @@ + From d961544b8b4cecc9fd674095fd268dcf3b0e1cee Mon Sep 17 00:00:00 2001 From: jvelilla Date: Thu, 8 Dec 2011 18:48:50 -0300 Subject: [PATCH 03/24] Updated restbucksCRUD documentation --- examples/restbucksCRUD/readme.md | 52 +++++++++++++++++++++++++++++++ examples/restbucksCRUD/readme.txt | 51 ------------------------------ 2 files changed, 52 insertions(+), 51 deletions(-) create mode 100644 examples/restbucksCRUD/readme.md diff --git a/examples/restbucksCRUD/readme.md b/examples/restbucksCRUD/readme.md new file mode 100644 index 00000000..0d11adbe --- /dev/null +++ b/examples/restbucksCRUD/readme.md @@ -0,0 +1,52 @@ +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. + + +How to Create an order + + * 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 + + { + "location":"takeAway", + "items":[ + { + "name":"Late", + "option":"skim", + "size":"Small", + "quantity":1 + } + ] + } + + + +How to Read an order + * Uri: http://localhost:8080/order/{order_id} + * Method: GET + + + + +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 + diff --git a/examples/restbucksCRUD/readme.txt b/examples/restbucksCRUD/readme.txt index dfff1b30..e69de29b 100644 --- a/examples/restbucksCRUD/readme.txt +++ b/examples/restbucksCRUD/readme.txt @@ -1,51 +0,0 @@ -Restbuck Eiffel Implementation based on the book of REST in Practice - - -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 - - * 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 - - { - "location":"takeAway", - "items":[ - { - "name":"Late", - "option":"skim", - "size":"Small", - "quantity":1 - } - ] - } - - - -How to Read an order - * Uri: http://localhost:8080/order/{order_id} - * Method: GET - - - - -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 0dd281257454d506069fc589b7f42d639332d5a9 Mon Sep 17 00:00:00 2001 From: jvelilla Date: Thu, 8 Dec 2011 20:04:39 -0200 Subject: [PATCH 04/24] 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 05/24] 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 06/24] 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 07/24] 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 08/24] 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 09/24] 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 10/24] 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 11/24] 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 12/24] 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 13/24] 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 14/24] 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 15/24] 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 16/24] 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 17/24] 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 18/24] 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 19/24] 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 20/24] 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 21/24] 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 From c0c206e9ae2420350b9a458bd68a42cd7f814e8e Mon Sep 17 00:00:00 2001 From: jvelilla Date: Fri, 9 Dec 2011 21:11:16 -0300 Subject: [PATCH 22/24] Update the restbuck_client, still work in progress. Update restbuck_server, remove unused class in inherit. Update libcurl_http_client_request, to parse context headers before the execution. Update wgi_input_stream, commented precondition. --- .../client/src/restbuck_client.e | 35 +++++++++++-------- examples/restbucksCRUD/src/restbucks_server.e | 2 -- .../libcurl/libcurl_http_client_request.e | 10 +++++- library/server/ewsgi/src/wgi_input_stream.e | 2 +- .../server/wsf/default/nino/default_service.e | 2 ++ 5 files changed, 33 insertions(+), 18 deletions(-) diff --git a/examples/restbucksCRUD/client/src/restbuck_client.e b/examples/restbucksCRUD/client/src/restbuck_client.e index dec021d0..bcaf158f 100644 --- a/examples/restbucksCRUD/client/src/restbuck_client.e +++ b/examples/restbucksCRUD/client/src/restbuck_client.e @@ -17,12 +17,26 @@ feature {NONE} -- Initialization local h: LIBCURL_HTTP_CLIENT sess: HTTP_CLIENT_SESSION + do + create h.make + sess := h.new_session ("http://127.0.0.1:8080") + -- Create Order + create_order (sess) + +-- if id /= Void and then attached sess.get ("/order/" + id, Void) as r then +-- print (r.body) +-- io.put_new_line +-- end + end + + + create_order (sess: HTTP_CLIENT_SESSION) + local s: READABLE_STRING_8 j: JSON_PARSER id: detachable STRING + context : HTTP_CLIENT_REQUEST_CONTEXT do - create h.make - sess := h.new_session ("http://127.0.0.1") s := "[ { "location":"takeAway", @@ -37,32 +51,25 @@ feature {NONE} -- Initialization } ]" - if attached sess.post ("/order", Void, s) as r then + create context.make + context.headers.put ("application/json", "Content-Type") + if attached sess.post ("/order", context, s) as r then + print (r.raw_header) + io.put_new_line if attached r.body as m then create j.make_parser (m) - if j.is_parsed and attached j.parse_object as j_o then if attached {JSON_STRING} j_o.item ("id") as l_id then id := l_id.item end print (m) io.put_new_line - end end end - if id /= Void and then attached sess.get ("/order/" + id, Void) as r then - print (r.body) - io.put_new_line - end end -feature -- Status - -feature -- Access - -feature -- Change feature {NONE} -- Implementation diff --git a/examples/restbucksCRUD/src/restbucks_server.e b/examples/restbucksCRUD/src/restbucks_server.e index be9f9da5..b0c9093c 100644 --- a/examples/restbucksCRUD/src/restbucks_server.e +++ b/examples/restbucksCRUD/src/restbucks_server.e @@ -12,8 +12,6 @@ inherit URI_TEMPLATE_ROUTED_SERVICE - ROUTED_SERVICE_HELPER - DEFAULT_SERVICE create diff --git a/library/client/http_client/src/spec/libcurl/libcurl_http_client_request.e b/library/client/http_client/src/spec/libcurl/libcurl_http_client_request.e index b29bfeee..9026d9dc 100644 --- a/library/client/http_client/src/spec/libcurl/libcurl_http_client_request.e +++ b/library/client/http_client/src/spec/libcurl/libcurl_http_client_request.e @@ -167,7 +167,15 @@ feature -- Execution p := curl.slist_append (p, curs.key + ": " + curs.item) end end - + if ctx /= Void then + if attached ctx.headers as l_headers_2 then + across + l_headers_2 as curs_2 + loop + p := curl.slist_append (p, curs_2.key + ": " + curs_2.item) + end + end + end p := curl.slist_append (p, "Expect:") curl_easy.setopt_slist (curl_handle, {CURL_OPT_CONSTANTS}.curlopt_httpheader, p) diff --git a/library/server/ewsgi/src/wgi_input_stream.e b/library/server/ewsgi/src/wgi_input_stream.e index 91a2a988..0fc87c28 100644 --- a/library/server/ewsgi/src/wgi_input_stream.e +++ b/library/server/ewsgi/src/wgi_input_stream.e @@ -27,7 +27,7 @@ feature -- Input read_string (nb: INTEGER) require is_open_read: is_open_read - not_end_of_input: not end_of_input +-- not_end_of_input: not end_of_input nb_large_enough: nb > 0 deferred ensure diff --git a/library/server/wsf/default/nino/default_service.e b/library/server/wsf/default/nino/default_service.e index 0eb3c0d1..42179264 100644 --- a/library/server/wsf/default/nino/default_service.e +++ b/library/server/wsf/default/nino/default_service.e @@ -17,11 +17,13 @@ feature {NONE} -- Initialization do port_number := 8080 base_url := "" + debug ("nino") print ("Example: start a Nino web server on port " + port_number.out + ", %Nand reply Hello World for any request such as http://localhost:" + port_number.out + "/" + base_url + "%N") end create app.make_custom (agent wgi_execute, base_url) + app.configuration.set_is_verbose (True) app.listen (port_number) end From a3c50956f1941bd559bf1900212c042a31317d18 Mon Sep 17 00:00:00 2001 From: jvelilla Date: Sat, 10 Dec 2011 11:02:20 -0200 Subject: [PATCH 23/24] Update examples/restbucksCRUD/readme.md --- examples/restbucksCRUD/readme.md | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/examples/restbucksCRUD/readme.md b/examples/restbucksCRUD/readme.md index f17c04d9..c833a939 100644 --- a/examples/restbucksCRUD/readme.md +++ b/examples/restbucksCRUD/readme.md @@ -145,7 +145,6 @@ Response success Date FRI,09 DEC 2011 20:34:20.00 GMT { - "id" : "1", "location" : "takeAway", "status" : "submitted", "items" : [ { @@ -164,6 +163,16 @@ If the GET request is SUCCESS, we response with 200 OK, and a representation of 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 + GET /order/1 HTTP/1.1 + Host: 127.0.0.1:8080 + Connection: keep-alive + 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 + If-None-Match: 6542EF270D91D3EAF39CFB382E4CEBA7 + +Response HTTP/1.1 200 OK Status 200 OK @@ -173,7 +182,6 @@ If is a Conditional GET and the resource does not change we send a 304, Resource etag 2ED3A40954A95D766FC155682DC8BB52 { - "id" : "1", "location" : "takeAway", "status" : "submitted", "items" : [ { @@ -208,7 +216,6 @@ But we change our decision and we want to stay in the shop. Expect: 100-Continue { - "id" : "1", "location" : "in shop", "status" : "submitted", "items" : [ { @@ -230,7 +237,6 @@ Response success Content-Length 122 { - "id" : "1", "location" : "in shop", "status" : "submitted", "items" : [ { From bf056154d8a927d252a0879d7aa1ae396e3da6e9 Mon Sep 17 00:00:00 2001 From: jvelilla Date: Sat, 10 Dec 2011 18:05:41 -0300 Subject: [PATCH 24/24] Update restbuck client, create and read an order. Update JSON converter, the id is not important, applied the DRY principle. Update the ORDER_HANDLER to use the meta_string_variable instead of meta_variable from req. Fix, the key in meta_variable_table, use c.key instead of c.item --- .../client/src/restbuck_client.e | 111 ++++++++++++++++-- .../src/domain/json_order_converter.e | 4 +- .../src/resource/order_handler.e | 41 ++++--- .../http_client/src/http_client_response.e | 8 +- library/server/wsf/src/wsf_request.e | 2 +- 5 files changed, 132 insertions(+), 34 deletions(-) diff --git a/examples/restbucksCRUD/client/src/restbuck_client.e b/examples/restbucksCRUD/client/src/restbuck_client.e index bcaf158f..2e0cd8b2 100644 --- a/examples/restbucksCRUD/client/src/restbuck_client.e +++ b/examples/restbucksCRUD/client/src/restbuck_client.e @@ -17,25 +17,102 @@ feature {NONE} -- Initialization local h: LIBCURL_HTTP_CLIENT sess: HTTP_CLIENT_SESSION + resp : HTTP_CLIENT_RESPONSE + l_location : detachable READABLE_STRING_8 + body : STRING do create h.make sess := h.new_session ("http://127.0.0.1:8080") -- Create Order - create_order (sess) + print ("%N Create Order %N") + resp := create_order (sess) --- if id /= Void and then attached sess.get ("/order/" + id, Void) as r then --- print (r.body) --- io.put_new_line --- end + -- Read the Order + print ("%N Read Order %N") + l_location := resp.headers.at ("Location") + resp := read_order (sess, l_location) + + + -- Update the Order + + if attached resp.body as l_body then + body := l_body.as_string_8 + body.replace_substring_all ("takeAway", "in Shop") + print ("%N Update Order %N") + resp := update_order (sess, l_location, body) + end + end + + update_order ( sess: HTTP_CLIENT_SESSION; uri : detachable READABLE_STRING_8; a_body : STRING) : HTTP_CLIENT_RESPONSE + local + l_headers: HASH_TABLE [READABLE_STRING_8,READABLE_STRING_8] + do + create Result.make + if attached uri as l_uri then + sess.set_base_url (l_uri) + Result := sess.put ("", Void, a_body ) + if attached Result as r then + -- Show headers + l_headers := r.headers + from + l_headers.start + until + l_headers.after + loop + print (l_headers.key_for_iteration) + print (":") + print (l_headers.item_for_iteration) + l_headers.forth + io.put_new_line + end + + -- Show body + print (r.body) + io.put_new_line + end + end end - create_order (sess: HTTP_CLIENT_SESSION) + read_order ( sess: HTTP_CLIENT_SESSION; uri : detachable READABLE_STRING_8) : HTTP_CLIENT_RESPONSE + local + l_headers: HASH_TABLE [READABLE_STRING_8,READABLE_STRING_8] + do + create Result.make + if attached uri as l_uri then + sess.set_base_url (l_uri) + Result := sess.get ("", Void) + if attached Result as r then + -- Show headers + l_headers := r.headers + from + l_headers.start + until + l_headers.after + loop + print (l_headers.key_for_iteration) + print (":") + print (l_headers.item_for_iteration) + l_headers.forth + io.put_new_line + end + + -- Show body + print (r.body) + io.put_new_line + end + end + end + + + + create_order (sess: HTTP_CLIENT_SESSION) : HTTP_CLIENT_RESPONSE local s: READABLE_STRING_8 j: JSON_PARSER id: detachable STRING context : HTTP_CLIENT_REQUEST_CONTEXT + l_headers: HASH_TABLE [READABLE_STRING_8,READABLE_STRING_8] do s := "[ { @@ -53,9 +130,24 @@ feature {NONE} -- Initialization create context.make context.headers.put ("application/json", "Content-Type") - if attached sess.post ("/order", context, s) as r then - print (r.raw_header) - io.put_new_line + Result := sess.post ("/order", context, s) + if attached Result as r then + -- Show the Headers + l_headers := r.headers + from + l_headers.start + until + l_headers.after + loop + print (l_headers.key_for_iteration) + print (":") + print (l_headers.item_for_iteration) + l_headers.forth + io.put_new_line + end + + + -- Show the Response body if attached r.body as m then create j.make_parser (m) if j.is_parsed and attached j.parse_object as j_o then @@ -67,7 +159,6 @@ feature {NONE} -- Initialization end end end - end diff --git a/examples/restbucksCRUD/src/domain/json_order_converter.e b/examples/restbucksCRUD/src/domain/json_order_converter.e index d911bf6a..711f6dd3 100644 --- a/examples/restbucksCRUD/src/domain/json_order_converter.e +++ b/examples/restbucksCRUD/src/domain/json_order_converter.e @@ -38,7 +38,7 @@ feature -- Conversion s_location ?= json.object (j.item (location_key), Void) s_status ?= json.object (j.item (status_key), Void) - create o.make (s_id, s_location, s_status) + create o.make ("", s_location, s_status) if attached {JSON_ARRAY} j.item (items_key) as l_val then l_array := l_val.array_representation @@ -87,7 +87,7 @@ feature -- Conversion jv: JSON_OBJECT do create Result.make - Result.put (json.value (o.id), id_key) +-- Result.put (json.value (o.id), id_key) Result.put (json.value (o.location), location_key) Result.put (json.value (o.status), status_key) from diff --git a/examples/restbucksCRUD/src/resource/order_handler.e b/examples/restbucksCRUD/src/resource/order_handler.e index b66b9fe5..561e31ac 100644 --- a/examples/restbucksCRUD/src/resource/order_handler.e +++ b/examples/restbucksCRUD/src/resource/order_handler.e @@ -66,9 +66,9 @@ feature -- HTTP Methods local etag_util : ETAG_UTILS do - if attached req.meta_variable ("HTTP_IF_NONE_MATCH") as if_none_match then + if attached req.meta_string_variable ("HTTP_IF_NONE_MATCH") as if_none_match then create etag_util - if if_none_match.as_string.same_string (etag_util.md5_digest (l_order.out).as_string_32) then + if if_none_match.same_string (etag_util.md5_digest (l_order.out).as_string_32) then Result := True end end @@ -108,26 +108,31 @@ feature -- HTTP Methods -- If the request is a Conditional PUT, and it does not mat we response -- 415, precondition failed. local - l_post: STRING + l_put: STRING l_order : detachable ORDER + id : STRING do - req.input.read_string (req.content_length_value.as_integer_32) - l_post := req.input.last_string - l_order := extract_order_request(l_post) - if l_order /= Void and then db_access.orders.has_key (l_order.id) then - if is_valid_to_update(l_order) then - if is_conditional_put (req, l_order) then - update_order( l_order) - compute_response_put (ctx, req, res, l_order) + if attached req.orig_path_info as orig_path then + id := get_order_id_from_path (orig_path) + req.input.read_string (req.content_length_value.as_integer_32) + l_put := req.input.last_string + l_order := extract_order_request(l_put) + if l_order /= Void and then db_access.orders.has_key (id) then + l_order.set_id (id) + if is_valid_to_update(l_order) then + if is_conditional_put (req, l_order) then + update_order( l_order) + compute_response_put (ctx, req, res, l_order) + else + handle_precondition_fail_response ("", ctx, req, res) + end else - handle_precondition_fail_response ("", ctx, req, res) + --| FIXME: Here we need to define the Allow methods + handle_resource_conflict_response (l_put +"%N There is conflict while trying to update the order, the order could not be update in the current state", ctx, req, res) end else - --| FIXME: Here we need to define the Allow methods - handle_resource_conflict_response (l_post +"%N There is conflict while trying to update the order, the order could not be update in the current state", ctx, req, res) + handle_bad_request_response (l_put +"%N is not a valid ORDER, maybe the order does not exist in the system", ctx, req, res) end - else - handle_bad_request_response (l_post +"%N is not a valid ORDER, maybe the order does not exist in the system", ctx, req, res) end end @@ -138,9 +143,9 @@ feature -- HTTP Methods etag_util : ETAG_UTILS do if attached retrieve_order (order.id) as l_order then - if attached req.meta_variable ("HTTP_IF_MATCH") as if_match then + if attached req.meta_string_variable ("HTTP_IF_MATCH") as if_match then create etag_util - if if_match.as_string.same_string (etag_util.md5_digest (l_order.out).as_string_32) then + if if_match.same_string (etag_util.md5_digest (l_order.out).as_string_32) then Result := True end else diff --git a/library/client/http_client/src/http_client_response.e b/library/client/http_client/src/http_client_response.e index bafa8523..c1b35088 100644 --- a/library/client/http_client/src/http_client_response.e +++ b/library/client/http_client/src/http_client_response.e @@ -41,7 +41,7 @@ feature -- Access raw_header: READABLE_STRING_8 -- Raw http header of the response. - headers: LIST [TUPLE [key: READABLE_STRING_8; value: READABLE_STRING_8]] + headers: HASH_TABLE[READABLE_STRING_8,READABLE_STRING_8] -- Computed table of http headers of the response. local tb: like internal_headers @@ -86,7 +86,7 @@ feature -- Access from until c <= n and not h[c].is_space loop c := c + 1 end - tb.force ([k, h.substring (c, l_end)]) + tb.put (h.substring (c, l_end), k) else check header_has_colon: c > 0 end end @@ -125,7 +125,9 @@ feature -- Change feature {NONE} -- Implementation - internal_headers: detachable ARRAYED_LIST [TUPLE [key: READABLE_STRING_8; value: READABLE_STRING_8]] +-- internal_headers: detachable ARRAYED_LIST [TUPLE [key: READABLE_STRING_8; value: READABLE_STRING_8]] -- Internal cached value for the headers + internal_headers: detachable HASH_TABLE[READABLE_STRING_8,READABLE_STRING_8] + -- Internal cached value for the headers end diff --git a/library/server/wsf/src/wsf_request.e b/library/server/wsf/src/wsf_request.e index ea92efd8..1e55d451 100644 --- a/library/server/wsf/src/wsf_request.e +++ b/library/server/wsf/src/wsf_request.e @@ -33,7 +33,7 @@ feature {NONE} -- Initialization across l_vars as c loop - meta_variables_table.force (new_string_value (c.key, c.item), c.item) + meta_variables_table.force (new_string_value (c.key, c.item), c.key) end else create meta_variables_table.make (0)