To continue with this content, please log in with your Data Access ID or create a new account.
Cancel Data Access ID
You may not be authorized to see this content. Please contact Data Access Europe for more information.
Cancel Data Access Europe
You are not authorized to see this content.
Cancel Data Access Europe
Next lesson:
Building our first handler
Cancel

Build HTTP Services in DataFlex

Lesson 2- The HTTP Handler Basics

This lesson will focus on the HTTP Handler API on the DataFlex side. In DataFlex code the HTTP Handler presents itself as a class, the cWebHttpHandler class. An object of this class is instantiated for the URLs that are to be handled. There can be multiple handlers within an application. This is configured using two properties: psPath and psVerbs. PsPath determines which URLs are handled, and psVerbs which filters out the request based on the type. The handling of the request is implemented by implementing the events of the class.

This example of the ACP handler shows the object being defined, and the simple HTML page that results. 

psPath is set to “SimpleHTTP.” In the resulting URL localhost is shown, followed by the directory, and then finally what psPath was set to. psPaths are flexible, wildcards cannot be used but multiple levels can be used simultaneously. Backslashes cannot be used. psPath maps to an IIS configuration path. 

The psVerb property is set to “*” by default, which means that it will handle any verb/request that comes in. It can be set to a single verb such as ‘GET,’ or set to a comma separated list of verbs. It is recommended to specify which verbs it is to handle. 

An example of when this is important are the OPTION requests for cross domain calls. By default, OPTION requests are handled by IIS. If they are set with psVerbs, the requests are intercepted, and IIS is prevented from doing what it is intended to do; sending out 404 or 500 errors for example.

The Events that can be used: 

  • OnPreRequest
  • OnPostRequst
  • OnHttpRequest
  • Verb specific events

peErrorType is another property that can be set on the HTTP handler. It defines the format of the errors that are sent back to the client that occur outside of the DataFlex code. Errors formats can be…

  • httpErrorHtml: basic HTML error page
  • httpErrorJson: standard JSON error
  • httpErrorSoap: SOAP style error
  • httpErrorEmpty: no error

This property cannot be changed at runtime.