Welcome to the SRP Forum! Please refer to the SRP Forum FAQ post if you have any questions regarding how the forum works.

Upgrade to v2.1

I am in the process of upgrading the existing HTTP_ routines that you provide, to the new version with my changes.

I now come to to my APIs and I see a big difference between your 'old' http_users_services and the new one.
I really dont want to hack my code that much, so, what would be the bare minimum changes I need to make for it to work in the new 'environment'

Here is a sample api you can use:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
Function HTTP_cars_Services(Service, Param1, Param2, Param3, Param4, Param5, Param6, Param7, Param8, Param9, Param10)
 
/***********************************************************************************************************************
 
    This program is proprietary and is not to be used by or disclosed to others, nor is it to be copied without written
    permission from Barry Stevens Business Software.
 
    Name        :   HTTP_cars_Services
 
    Description :   Handler program for the HTTP cars service module.
 
    Notes       :   The generic parameters should contain all the necessary information to process the services. Often
                    this will be information like the data Record and Key ID.
 
    Parameters  :
        Service         [in] -- Name of the service being requested
        Param1-10   [in/out] -- Additional request parameter holders
        Response       [out] -- Response to be sent back to the Controller (MCP) or requesting procedure
 
    Metadata    :
        @@DEFINE_SERVICES_SIGNATURE(@SERVICE, @PARAMS)
        @@DEFINE_UNQUOTED_OPTIONS BOOLEAN(True$, False$)
 
    History     :   (Date, Initials, Notes)
        14/04/15    dmb     Original programmer. (http_contacts_services)
        1/06/15     bjs     ex http_coffin_services changed for parsons project
 
***********************************************************************************************************************/
declare function HTTP_bsbs_match_search
 
$insert APP_INSERTS
$insert HTTP_SERVICE_SETUP
$insert HTTP_INSERTS
 
$insert accessible_columns
 
ValidMethod         = True$ ; // Assume the HTTP method is valid until proven otherwise.
DescriptionSearch   = HTTP_Services('GetQueryField', 'search')
 
Begin Case
    Case Len(Service)
        // This means the URL ends with /coffin/<id>. The client is requesting a specific coffin item.
        SelfURL = HTTP_Services('GetSelfURL')
         
        Begin Case
            Case HTTPMethod _EQC 'GET'      ;   GoSub GetItem
            Case HTTPMethod _EQC 'OPTIONS'  ;   GoSub OptionsItem
            Case Otherwise$                 ;   ValidMethod = False$
        End Case
         
    Case Len(DescriptionSearch)
        // This means the URL ends with /coffin?search=<string>. The client is searching for matching coffin items.
        SelfURL = HTTP_Services('GetSelfURL')
         
        Begin Case
            Case HTTPMethod _EQC 'GET'      ;   GoSub GetSearch
            Case HTTPMethod _EQC 'OPTIONS'  ;   GoSub OptionsSearch
            Case Otherwise$                 ;   ValidMethod = False$
        End Case
         
    Case Service _EQC ''
        // This means the URL ends with /coffin. The client is requesting a collection of all coffins.
        SelfURL = HTTP_Services('GetSelfURL')
         
        Begin Case
            Case HTTPMethod _EQC 'GET'      ;   GoSub Get
            Case HTTPMethod _EQC 'OPTIONS'  ;   GoSub Options
            Case Otherwise$                 ;   ValidMethod = False$
        End Case
         
    Case Otherwise$
        HTTP_Services('SetResponseStatus', 404, Service : ' is not a valid service request within the ' : CurrentServiceHandler : ' module.')
End Case
 
If Not(ValidMethod) then
    HTTP_Services('SetResponseStatus', 405, HTTPMethod : ' is not valid for this service.')
    HTTP_Services('SetResponseHeaderField', 'Allow', 'GET', True$)
    HTTP_Services('SetResponseHeaderField', 'Allow', 'OPTIONS', True$)
end
 
If Assigned(Response) else Response = ''
 
Return Response
 
 
//----------------------------------------------------------------------------------------------------------------------
// GetItem
//
// @@DEFINE_SERVICE(GetItem)
//
// Returns the item requested in HAL+JSON format.
//----------------------------------------------------------------------------------------------------------------------
GetItem:
    ItemID  = Service
    HAL     = ''    ; // Initialize the response.
     
    // Put logic here that creates the item resource. Likely this means reading a database row and returning one or
    // more database column names and their respective values. For testing purposes, 1111 will be an invalid ItemID
    // but all other ItemIDs be accepted.
    If rowexists("RESOURCES",ItemID) then
        if xlate("RESOURCES",ItemID,"NOT_CURRENT","X") then
             
            HTTP_Services('SetResponseStatus', 200, ItemID:' was found in the RESOURCES file. But it is non current.')
             
        end else
            gosub SetUpColumnNames
             
            ItemID  = Service
             
            HAL     = HTTP_Resource_Services('GetDatabaseItem', 'RESOURCES', SelfURL, ItemID,ColumnNames)
            HTTP_Services('SetResponseBody', HAL, False$)
             
            // Use the Response variable for internal monitoring, tracking, and debugging. This does not affect the HTTP
            // response.
            Response    = HAL
        end
    end else
        // This ItemID does not exist so set a 404 status code.
        HTTP_Services('SetResponseStatus', 200, ItemID : ' is not a valid Car identifier.')
    end
     
    // Use the Response variable for internal monitoring, tracking, and debugging. This does not affect the HTTP
    // response.
    Response    = HAL
return
 
 
//----------------------------------------------------------------------------------------------------------------------
// OptionsItem
//
// @@DEFINE_SERVICE(OptionsItem)
//
// Sets the appropriate response header fields for an OPTIONS request.
//----------------------------------------------------------------------------------------------------------------------
OptionsItem:
    HTTP_Services('SetResponseHeaderField', 'Access-Control-Allow-Headers', 'authorization', True$)
    HTTP_Services('SetResponseHeaderField', 'Access-Control-Allow-Headers', 'x-authorization', True$)
    HTTP_Services('SetResponseHeaderField', 'Access-Control-Max-Age', 1728000)
    HTTP_Services('SetResponseHeaderField', 'Allow', 'GET', True$)
    HTTP_Services('SetResponseHeaderField', 'Allow', 'OPTIONS', True$)
return
 
 
//----------------------------------------------------------------------------------------------------------------------
// GetSearch
//
// @@DEFINE_SERVICE(GetSearch)
//
// Returns the matching items requested in HAL+JSON format.
//----------------------------------------------------------------------------------------------------------------------
GetSearch:
    HAL     = ''    ; // Initialize the response.
     
    // Put logic here that searches for all matches to the description. If there is at least one match then create
    // a collection of embedded items. Sort as needed since they will be returned in the order they are passed into the
    // SetHALCollectionEmbedded service. For testing purposes, only 'shaded' will match any database rows.
    MatchedItems    = False$    ; // Assume false for now.
    ItemIDs=HTTP_bsbs_match_search("RESOURCES","DESCRIPTION_XREF",DescriptionSearch,"S","CATEGORY","CARS")
    convert @vm to @fm in ItemIDs
     
    If error_services('NoError') and ItemIDs then
        // A match was found. Create the rows
        gosub SetUpColumnNames
         
        HAL         = HTTP_Resource_Services('GetDatabaseItems', ItemIDs, 'RESOURCES', SelfURL, ColumnNames)
         
        HTTP_Services('SetResponseBody', HAL, False$)
    end else
        // No matches were found so set a 404 status code.
        StatusMsg=error_services("GetMessages")
        HTTP_Services('SetResponseStatus', 200, StatusMsg)
    end
     
    Response    = HAL
return
 
 
//----------------------------------------------------------------------------------------------------------------------
// OptionsSearch
//
// @@DEFINE_SERVICE(OptionsSearch)
//
// Sets the appropriate response header fields for an OPTIONS request.
//----------------------------------------------------------------------------------------------------------------------
OptionsSearch:
    HTTP_Services('SetResponseHeaderField', 'Access-Control-Allow-Headers', 'authorization', True$)
    HTTP_Services('SetResponseHeaderField', 'Access-Control-Allow-Headers', 'x-authorization', True$)
    HTTP_Services('SetResponseHeaderField', 'Access-Control-Max-Age', 1728000)
    HTTP_Services('SetResponseHeaderField', 'Allow', 'GET', True$)
    HTTP_Services('SetResponseHeaderField', 'Allow', 'OPTIONS', True$)
return
 
 
//----------------------------------------------------------------------------------------------------------------------
// Get
//
// @@DEFINE_SERVICE(Get)
//
// Returns all items in HAL+JSON format.
//----------------------------------------------------------------------------------------------------------------------
Get:
    HAL         = ''    ; // Initialize the response.
     
    gosub SetUpColumnNames
    Filter      = "SELECT RESOURCES BY DESCRIPTION WITH CATEGORY EQ 'CARS' AND WITHOUT NOT_CURRENT"
    HAL         = HTTP_Resource_Services('GetDatabaseItems', Filter, 'RESOURCES', SelfURL,ColumnNames)
     
    Response    = HAL
return
 
 
//----------------------------------------------------------------------------------------------------------------------
// Options
//
// @@DEFINE_SERVICE(Options)
//
// Sets the appropriate response header fields for an OPTIONS request.
//----------------------------------------------------------------------------------------------------------------------
Options:
    HTTP_Services('SetResponseHeaderField', 'Access-Control-Allow-Headers', 'authorization', True$)
    HTTP_Services('SetResponseHeaderField', 'Access-Control-Allow-Headers', 'x-authorization', True$)
    HTTP_Services('SetResponseHeaderField', 'Access-Control-Max-Age', 1728000)
    HTTP_Services('SetResponseHeaderField', 'Allow', 'GET', True$)
    HTTP_Services('SetResponseHeaderField', 'Allow', 'OPTIONS', True$)
return
 
GetPhotoFiles:
     
    StockId=ItemID
    Path=xlate("CONTROL_FILE",1,"DEFAULT_FOLDER_RESOURCES_PHOTOS","X")
    If Path then
        PathFuneralId=StockID
        if PathFuneralId=null$ then PathFuneralId=9999999999
        If path[-1,1]="\" Then path[-1,1]=null$
        Path:="\"
        PathFile=Path:PathFuneralID:" ":"*.*"
        PDFEnabled=false$
        InitDir PathFile
        PDFFiles = dirList()
        if PDFFiles then           
            PDFEnabled=1
        end
        Transfer PDFFiles To PDFFilesWork
         
        position = 1
        flag  = ""
        Loop
            Remove PDFFile From PDFFilesWork At position Setting flag
            xPDFFile=PDFFile[1,'.']
            xPDFFile[1,Len(PathFuneralId)]=null$
            If not(xPDFFile=null$) then
                PDFFiles:=Path:PDFFile:@vm
            end
        While flag
        Repeat
        PDFFiles[-1,1]=null$
    end
     
     
return
 
SetUpColumnNames:
     
    ColumnNames= ''
    ColumnNames:=   "DESCRIPTION":@fm
    ColumnNames:=   "ITEM_GST_PRICE":@fm
    ColumnNames:=   "PHOTO_FILE_PATHS":@fm
     
    ColumnNames[-1,1]=null$
     
     
end

Comments

  • OK, looks like I might have gotten away with:

    Function HTTP_cars_Services(RemainingURL)
    .
    .
    Service=NextSegment

    Begin Case
    Case Len(Service)
  • ooops and also

    Case Service _EQC '' replaced by Case RemainingURL _EQC ''
  • Barry,

    Hopefully you understand that retrofitting your entire HTTP service is not something we would consider "support". We provided you full source code so you could do this yourself. Support is helping you with unexpected behavior or, perhaps, helping to answer the "why" and "how" questions.
  • But you changed the http_framework modules on me, so i have to.
    You called it retrofitting in your changes to http_users_services.
  • Anyway, happy to go it alone and see what happens.
Sign In or Register to comment.