Update examples/restbucksCRUD/readme.md
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
Restbuck Eiffel Implementation based on the book of REST in Practice
|
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.
|
||||||
<table>
|
<table>
|
||||||
<TR><TH>Verb</TH> <TH>URI or template</TH> <TH>Use</TH></TR>
|
<TR><TH>Verb</TH> <TH>URI or template</TH> <TH>Use</TH></TR>
|
||||||
<TR><TD>POST</TD> <TD>/order</TD> <TD>Create a new order, and upon success, receive a Locationheader specifying the new order's URI.</TD></TR>
|
<TR><TD>POST</TD> <TD>/order</TD> <TD>Create a new order, and upon success, receive a Locationheader specifying the new order's URI.</TD></TR>
|
||||||
@@ -9,7 +10,80 @@ This is an implementation of CRUD pattern for manipulate resources
|
|||||||
<TR><TD>DELETE</TD> <TD>/order/{orderId}</TD> <TD>Logically remove the order identified by the given URI.</TD></TR>
|
<TR><TD>DELETE</TD> <TD>/order/{orderId}</TD> <TD>Logically remove the order identified by the given URI.</TD></TR>
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
|
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
|
How to Create an order
|
||||||
|
----------------------
|
||||||
|
|
||||||
* Uri: http://localhost:8080/order
|
* Uri: http://localhost:8080/order
|
||||||
* Method: POST
|
* Method: POST
|
||||||
|
|||||||
Reference in New Issue
Block a user