|
| 1 | +-- ============================================================================ |
| 2 | +-- Published REST Service Examples |
| 3 | +-- ============================================================================ |
| 4 | +-- |
| 5 | +-- Demonstrates creating, describing, and dropping published REST services. |
| 6 | +-- |
| 7 | +-- Prerequisites: |
| 8 | +-- - Microflows backing the operations must exist |
| 9 | +-- |
| 10 | +-- ============================================================================ |
| 11 | + |
| 12 | +CREATE MODULE PrsTest; |
| 13 | + |
| 14 | +-- ############################################################################ |
| 15 | +-- PART 1: BACKING MICROFLOWS |
| 16 | +-- ############################################################################ |
| 17 | + |
| 18 | +CREATE MICROFLOW PrsTest.PRS_GetAllOrders ($httpResponse: System.HttpResponse) |
| 19 | +RETURNS String AS $Result |
| 20 | +BEGIN |
| 21 | + DECLARE $Result String = '[]'; |
| 22 | + RETURN $Result; |
| 23 | +END; |
| 24 | +/ |
| 25 | + |
| 26 | +CREATE MICROFLOW PrsTest.PRS_GetOrderById ($httpResponse: System.HttpResponse, $Id: String) |
| 27 | +RETURNS String AS $Result |
| 28 | +BEGIN |
| 29 | + DECLARE $Result String = '{}'; |
| 30 | + RETURN $Result; |
| 31 | +END; |
| 32 | +/ |
| 33 | + |
| 34 | +CREATE MICROFLOW PrsTest.PRS_CreateOrder ($httpResponse: System.HttpResponse) |
| 35 | +RETURNS String AS $Result |
| 36 | +BEGIN |
| 37 | + DECLARE $Result String = '{"status": "created"}'; |
| 38 | + RETURN $Result; |
| 39 | +END; |
| 40 | +/ |
| 41 | + |
| 42 | +CREATE MICROFLOW PrsTest.PRS_DeleteOrder ($httpResponse: System.HttpResponse, $Id: String) |
| 43 | +RETURNS String AS $Result |
| 44 | +BEGIN |
| 45 | + DECLARE $Result String = '{"status": "deleted"}'; |
| 46 | + RETURN $Result; |
| 47 | +END; |
| 48 | +/ |
| 49 | + |
| 50 | +CREATE MICROFLOW PrsTest.PRS_GetCustomers ($httpResponse: System.HttpResponse) |
| 51 | +RETURNS String AS $Result |
| 52 | +BEGIN |
| 53 | + DECLARE $Result String = '[]'; |
| 54 | + RETURN $Result; |
| 55 | +END; |
| 56 | +/ |
| 57 | + |
| 58 | +-- ############################################################################ |
| 59 | +-- PART 2: SIMPLE PUBLISHED REST SERVICE |
| 60 | +-- ############################################################################ |
| 61 | + |
| 62 | +CREATE PUBLISHED REST SERVICE PrsTest.OrderAPI ( |
| 63 | + Path: 'rest/orders/v1', |
| 64 | + Version: '1.0.0', |
| 65 | + ServiceName: 'Order API' |
| 66 | +) |
| 67 | +{ |
| 68 | + RESOURCE 'orders' { |
| 69 | + GET '/' MICROFLOW PrsTest.PRS_GetAllOrders; |
| 70 | + GET '/{id}' MICROFLOW PrsTest.PRS_GetOrderById; |
| 71 | + POST '/' MICROFLOW PrsTest.PRS_CreateOrder; |
| 72 | + DELETE '/{id}' MICROFLOW PrsTest.PRS_DeleteOrder; |
| 73 | + } |
| 74 | +}; |
| 75 | + |
| 76 | +DESCRIBE PUBLISHED REST SERVICE PrsTest.OrderAPI; |
| 77 | + |
| 78 | +-- ############################################################################ |
| 79 | +-- PART 3: MULTI-RESOURCE SERVICE |
| 80 | +-- ############################################################################ |
| 81 | + |
| 82 | +CREATE PUBLISHED REST SERVICE PrsTest.CrmAPI ( |
| 83 | + Path: 'rest/crm/v1', |
| 84 | + Version: '1.0.0', |
| 85 | + ServiceName: 'CRM API' |
| 86 | +) |
| 87 | +{ |
| 88 | + RESOURCE 'orders' { |
| 89 | + GET '/' MICROFLOW PrsTest.PRS_GetAllOrders; |
| 90 | + } |
| 91 | + RESOURCE 'customers' { |
| 92 | + GET '/' MICROFLOW PrsTest.PRS_GetCustomers; |
| 93 | + } |
| 94 | +}; |
| 95 | + |
| 96 | +DESCRIBE PUBLISHED REST SERVICE PrsTest.CrmAPI; |
| 97 | + |
| 98 | +-- ############################################################################ |
| 99 | +-- PART 4: CREATE OR REPLACE |
| 100 | +-- ############################################################################ |
| 101 | + |
| 102 | +CREATE OR REPLACE PUBLISHED REST SERVICE PrsTest.CrmAPI ( |
| 103 | + Path: 'rest/crm/v2', |
| 104 | + Version: '2.0.0', |
| 105 | + ServiceName: 'CRM API v2' |
| 106 | +) |
| 107 | +{ |
| 108 | + RESOURCE 'orders' { |
| 109 | + GET '/' MICROFLOW PrsTest.PRS_GetAllOrders; |
| 110 | + GET '/{id}' MICROFLOW PrsTest.PRS_GetOrderById; |
| 111 | + } |
| 112 | + RESOURCE 'customers' { |
| 113 | + GET '/' MICROFLOW PrsTest.PRS_GetCustomers; |
| 114 | + } |
| 115 | +}; |
| 116 | + |
| 117 | +DESCRIBE PUBLISHED REST SERVICE PrsTest.CrmAPI; |
| 118 | + |
| 119 | +-- ############################################################################ |
| 120 | +-- PART 5: SHOW AND LIST |
| 121 | +-- ############################################################################ |
| 122 | + |
| 123 | +SHOW PUBLISHED REST SERVICES; |
| 124 | +SHOW PUBLISHED REST SERVICES IN PrsTest; |
| 125 | + |
| 126 | +-- ############################################################################ |
| 127 | +-- PART 6: DROP |
| 128 | +-- ############################################################################ |
| 129 | + |
| 130 | +DROP PUBLISHED REST SERVICE PrsTest.OrderAPI; |
| 131 | + |
| 132 | +SHOW PUBLISHED REST SERVICES IN PrsTest; |
| 133 | + |
| 134 | +-- ============================================================================ |
| 135 | +-- END OF PUBLISHED REST SERVICE EXAMPLES |
| 136 | +-- ============================================================================ |
0 commit comments