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:

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.