Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

HTTP services use a standard commuter module style routing block. This uses a case statement syntax to interpret the arguments and route the request to the appropriate destination. Here is a template:

Code Block
languagebp
titleRouter Block
ValidMethod = True$ ; // Assume the HTTP method is valid until proven otherwise.

Begin Case
   Case Service _EQC ''
       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 Service _EQC 'aaa'
       HTTP_Services('RunHTTPService', NextServiceHandler, NextService, NextURL)

   Case Service _EQC 'bbb'
       HTTP_Services('RunHTTPService', NextServiceHandler, NextService, NextURL)

   Case Service _EQC 'ccc'
       HTTP_Services('RunHTTPService', NextServiceHandler, NextService, NextURL)

   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

...